You must have observed that the state of checkboxes are not persisted after screen mode changes from landscape to portrait and vice versa. This is a very important concept that we should be aware of. For every screen orientation change, the activity is destroyed, and then recreated. The
onCreate()
method is called and hence, the current state of the activity is lost. We need to save the state using the onSaveInstanceSate
method and get it back with the onRestoreInstanceState
method. So let's override these methods to achieve this with the following code:
@Override public void onSaveInstanceState(Bundle outState) { //---save whatever you need to persist— outState.putBoolean("mileChecked",cBoxMile.isChecked()); outState.putBoolean("ydChecked",cBoxYd.isChecked()); outState.putBoolean("ftchecked",cBoxFt.isChecked()); super.onSaveInstanceState(outState); } @Override...