Skip to content Skip to sidebar Skip to footer

Android Save Game State In Onpause Or Ondestroy?

I am trying to implement a 'resume' feature for a game I'm developing. It should work as follows: If the user starts a game and later closes the game with finishing, the game stat

Solution 1:

Despite this, I cannot find anywhere recommending to save state in onDestroy() and everyone seems to recommend using onPause. Am I missing a piece of information here?

You are :). onDestroy() is not guaranteed to be called. See the documentation for it:

Note: do not count on this method being called as a place for saving data! For example, if an activity is editing data in a content provider, those edits should be committed in either onPause() or onSaveInstanceState(Bundle), not here. This method is usually implemented to free resources like threads that are associated with an activity, so that a destroyed activity does not leave such things around while the rest of its application is still running. There are situations where the system will simply kill the activity's hosting process without calling this method (or any others) in it, so it should not be used to do things that are intended to remain around after the process goes away.

Post a Comment for "Android Save Game State In Onpause Or Ondestroy?"