title: android game - keeping track of time
body: <p>I have a puzzle game for android. When the puzzle starts I take the current time:</p>
  
  <p><code>long startTime = System.currentTimeInMillis()</code></p>
  
  <p>When the player completes the puzzle, I take the time again, subtract the starting time and work out the elapsed time. This is all ok.</p>
  
  <p>My problem is what to do when the application is interrupted. For example by a phone call. At the moment, the puzzle remains in it's previous state automatically (as it is in a view). However, the calculation <code>completionTime = currentTime - startTime</code> will now be invalid.</p>
  
  <p>I have tried saving the elapsed time using <code>onSaveInstaceState(Bundle)</code>. However its counterpart, <code>onRestoreInstanceState(Bundle)</code> is not called when re-entering the app. Rather, the <code>onResume()</code> method is called instead? I have read this is because the app has not been 'killed', rather it is still in memory. In the case of a 'kill', I'd imagine the state of the View will also be lost? I don't think it's terribly necessary to keep track of the view in this case, so I won't worry about the time either.</p>
  
  <p>Is there a way to read a bundle from onResume(), should I just implement a shared preference? </p>
  
  <p>I'd like to avoid updating the elapsed time in the game loop as this seems inefficient.</p>