public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.some_layout);
toggleButton=(ToggleButton) findViewById(R.id.toggleButton1);
}
@Override
public void onSaveInstanceState(Bundle save) {
super.onSaveInstanceState(save);
save.putBoolean("ToggleButtonState", toggleButton.isChecked());
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
toggleButton.setChecked(savedInstanceState.getBoolean("ToggleButtonState",false);
}
It seem like it should work, but if i do the following:
- run my application by its icon on applications menu
- checking the toggle button
- going back to home screen by pressing the back button
- activating my application from its icon again
i get to see my toggle button unchecked, why is it so? and how do i overcome this?