I have a puzzle game for Android. When the puzzle begins, I take the current time:
long startTime = System.currentTimeInMillis()
When the player completes the puzzle, I again take the time, subtract the start time and worked out the elapsed time. Everything is good.
My problem is what to do when the application is interrupted. For example, by phone. At the moment, the puzzle remains in its previous state automatically (as you can see). However, the calculation of completionTime = currentTime - startTime will now be invalid.
I tried to save the elapsed time using onSaveInstaceState(Bundle) . However, its duplicate onRestoreInstanceState(Bundle) not called when you re- onRestoreInstanceState(Bundle) application. Rather, the onResume() method is called instead? I read this because the application was not "killed", rather, it is still in memory. In the case of a โmurder,โ I would suggest that the state of the submission will also be lost? I donโt think it is terribly necessary to keep track of opinions in this case, so I wonโt worry about time either.
Is there a way to read the package from onResume (), should I implement general preferences?
I would like to avoid updating the elapsed time in the game loop, as this seems inefficient.
Wozza source share