title: Metronome Timer slowdown (via Handler, or Threads too)
body: <p>I have a simple, classic, statement that every 200 milliseconds plays a sound (a metronome).</p>
  
  <p>I wrote it using Handlers, and then in another way, using Threads.
  The problem is the same in both ways: when I press hardware home button, or also simply when I press a button to open a ListView, the metronome terribly slowdown for a while. </p>
  
  <p>This problem (not so strong, but however present) presents also doing nothing and leaving the application in foreground.</p>
  
  <p>Any ideas? </p>
  
  <p>Here's the code:</p>
  
  <p>public class Metronome implements Runnable{</p>
  
  <pre><code>private Handler mHandler = new Handler();
  public static long mStartTime;
  
  Main mainContext; 
  
  public Metronomo(Main context) {
      mainContext = context;
  }
  
  
  public void play() {
      mStartTime = System.currentTimeMillis();
      mHandler.postDelayed(this, 100);
  }
  
  public final void stop(){
      mHandler.removeCallbacks(this);
  }
  
  public void run(){
          //play the ogg file in position 1
          mSoundManager.playSound(1);
  
          //reschedule the next playing after 200ms
          mHandler.postAtTime(this, SystemClock.uptimeMillis() + 200);
     }
  </code></pre>
  
  <p>};</p>