これは、Androidの共有設定を使用して実行できるはずです:http://developer.android.com/guide/topics/data/data-storage.html#pref
ブール値を格納して、レイアウトの状態を追跡できます(5つのボタンがあるRelativeLayoutであるか、4つのボタンがあるView選択状態であるか)。このように、アクティビティをロードするときに、最初にこのフラグをチェックして、ロードするレイアウトを決定できます。このフラグ変数を初期化する必要がないように設定を使用することもできますが、代わりにデフォルト値を使用できます。
public class MyActivity extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
public enum ViewState {
NO_CLICK, VIEW_A, VIEW_B, ...
};
@Override
protected void onCreate(Bundle state){
super.onCreate(state);
. . .
// Restore preferences
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
int currentView = settings.getInt("viewClicked", NO_CLICK);
switch(currentView)
{
case VIEW_A: // Load the view if button A was clicked
loadViewA();
break;
case VIEW_B: // Load the view if button B was clicked
loadViewB();
break;
...
case NO_CLICK: // Load the RelativeLayout with 5 Buttons
default:
loadDefaultView();
break;
}
}
そして、ボタンAのOnClickListenerで:
public void onClick(View v) {
...
// Get the settings
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("viewClicked", VIEW_A);
// Commit the edits!
editor.commit();
// Load the view
loadViewA();
}
他のボタンの他のonClick()メソッドも同様に実装できます。
編集:ブール値ではなく整数を使用するように更新