Android Developer Question:
Download Questions PDF

Explain me onSavedInstanceState() and onRestoreInstanceState() in activity?

Answer:

OnRestoreInstanceState() - When activity is recreated after it was previously destroyed, we can recover the saved state from the Bundle that the system passes to the activity. Both the onCreate() and onRestoreInstanceState() callback methods receive the same Bundle that contains the instance state information. But because the onCreate() method is called whether the system is creating a new instance of your activity or recreating a previous one, you must check whether the state Bundle is null before you attempt to read it. If it is null, then the system is creating a new instance of the activity, instead of restoring a previous one that was destroyed.
onSaveInstanceState() - is a method used to store data before pausing the activity.

Download Android Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Explain me what is the difference between Service and IntentService? How is each used?Please explain the onTrimMemory() method?