All the sources I read have all mentioned couple of cases and concluded with \"a few other cases\". What are ALL the cases when the onSaveInstanceState method called in a Vi
Whenever there is as soft kill of the activity. I.e when the orientation changes or when the process is killed by android due to low memory.
It's not called when the user knowingly just navigates away from the activity.
Refer to this link: https://sites.google.com/site/jalcomputing/home/mac-osx-android-programming-tutorial/saving-instance-state
onSaveInstanceState is called when ever activity is out of veiw.. like when u press home key, onSaveInstanceState is called.
The doc says
This method is called before an activity may be killed so that when it comes back some time in the future it can restore its state.
As per doc
If the user interacts with an activity and presses the Back button or if the finish() method of an activity is called, the activity is removed from the current activity stack and recycled. In this case there is no instance state to save and the onSaveInstanceState() method is not called.
If the user interacts with an activity and presses the Home button, the activity instance state must be saved. The onSaveInstanceState() method is called. If the user restarts the application it will resume or restart the last running activity. If it restarts the activity it provides the bundle with the save data to the onRestoreInstanceState() and onCreate() methods.
If you override onSaveInstanceState() and onRestoreInstanceState() you should call the super implementation of it, because the default views of Android store their data via a call to View.onSaveInstanceState from the onSaveInstanceState() method of the activity. For example EditText stores its content via the default call of this method.
Also be aware that onSaveInstanceState
can be called on a fragment directly after onCreate
(onCreateView
, onActivityCreated
, onStart
, and onResume
will NOT be called), if the fragment is attached to an activity but not shown, then destroyed. Thus you need to be sure that everything you reference in onSaveInstanceState
is initialized in onCreate
, otherwise you risk a NullPointerException
.
This method did not call when user presses "return" button,this is one of that case..