By default Activity
handles its components state which has an id
attribute.
If it's not acting like that, you can use onSaveInstanceState
and onRestoreInstanceState
to handle components state manually:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putBoolean("Toggle1", toggle.isChecked());
// etc.
}
And to restore the state:
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
boolean toggle1State = savedInstanceState.getBoolean("Toggle1");
toggle1.setCheched(toggle1State);
}