Activity life cycle

From http://androidcookbook.com/Recipe.seam?recipeId=2688

onSaveInstanceState(Bundle) and onPause()
Use onPause to save data that should be preserved long term, use onSaveInstanceState for transient states. For example in a game the current score could be saved in onSaveInstanceState and only saved in onPause if it was good enough for the High Score table, in which cause the High Score table (in SharedPreferences, a database table, or a file) is updated.


onSaveInstanceState\onRestoreInstanceState and the Android Lifecycle
The SDK documentation says that onSaveInstanceState(Bundle) may run just before or just after onPause(). As foronRestoreInstanceState(Bundle) that occurs after onStart() and before onResume().

onSaveInstanceState() is not called when the user navigates to another activity. So if the user presses the back button, this callback won't be called. But if the Android home button is pressed this callback is called.

Comments

Popular posts from this blog

endmenu in different file than menu?

Multi Threading in Android

A binary with debug symbols with the Android NDK