O'Reilly logo

Android Development Tools for Eclipse by Sanjay Shah, Khirulnizam Abd Rahman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Persisting the state information during the state transition

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()); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required