title: Timer Stops working when screen turn off
body: <p>Hi im a newbie in Android &amp; java lang.
  i have this code that tells you how long have you been playing.
  the code works fine, except when the screen turns off or when the user press the power button (sleep mode) it stop working.
  can any one suggest a simple code to keep my time counting even when the screen is off or in sleep mode.  Thanks...</p>
  
  <pre><code>public class test extends Activity 
  {
      Handler mHandler = new Handler();
  
      Runnable mUpdateTime = new Runnable() 
      {
          public void run() 
          { 
              sec += 1;
              if(sec &gt;= 60) 
              {
                  sec = 0;
                  min += 1;
                  if (min &gt;= 60) 
                  {
                      min = 0;
                      hour += 1;
                  }
              }
              playtime.setText(String.format("%02d:%02d:%02d", hour, min, sec));
              mHandler.postDelayed(mUpdateTime, 1000);
          }
      };
  
  
      @Override
      public void onCreate(Bundle savedInstanceState) 
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          mHandler.postDelayed(mUpdateTime, 1000);
      }
  }
  </code></pre>