title: Android thread pause in standby
body: <p>I'm trying to write a simple Activity with a thread that write a value in a text files every N seconds. </p>
  
  <p>The problem is that after some minutes I've run the Activity, with the phone in standby, the thread sometime stops for a larger time, even minutes.</p>
  
  <p>In the Run() I've to write the file than sleep for N seconds. </p>
  
  <pre><code>public void run() {
      isrunning = true;
  int cont=0;
      try {
          while (isrunning)
          {
              es.writeSD("- THREAD:" + cont, true);
              Thread.sleep(1000);
              es.writeSD("- THREAD - sending: " + cont,true);             
              cont++;
          }
      } 
      catch (InterruptedException e) {
          es.writeSD("- THREAD - InterruptedException: " + e.getMessage(),true);
      }
      catch (Exception e) {
          es.scriviSD("- THREAD - Exception: " + e.getMessage(),true);
      }   
  }
  </code></pre>
  
  <p>This is the log with the timestamp</p>
  
  <p>20130911T154448 : - THREAD:36</p>
  
  <p>20130911T154449 : - THREAD sending: 36</p>
  
  <p><strong>20130911T154449</strong> : - THREAD:37</p>
  
  <p><strong>20130911T154652</strong> : - THREAD sending: 37</p>
  
  <p>20130911T154652 : - THREAD:38</p>
  
  <p>20130911T154656 : - THREAD sending: 38</p>