1.

If you rotate your phone how it will save data in the background. Which lifecycle methods will call?

Answer»

Having rotated the device, the following state change sequence should appear Clearly this has RESULTED in the activity being destroyed and re-created. To save the state information override onSaveInstanceState() method and add key-value pairs to the BUNDLE OBJECT. It will save data in the EVENT that your activity is destroyed unexpectedly. This method gets called before onStop(). To get saved from an activity state, we are using method onRestoreInstanceState.

The first step in extending the StateChange application is to make sure that the text entered by the user is extracted from the EditText component within the onSaveInstanceState() method of the StateChangeActivity activity and then saved as a key-value pair into the Bundle object.

Alternately, use the onRestoreInstanceState( ) method to EXTRACT saved state from the Bundle and restore it into new instances of the activity.  The onRestoreInstanceState( ) method is another callback lifecycle method that is also rarely seen in the activity lifecycle diagrams. The onRestoreInstanceState( ) method is automatically invoked by Android between the onStart( ) and the onResume( ) lifecycle methods.



Discussion

No Comment Found

Related InterviewSolutions