title: Android Handler.postDelayed interrupts sound playing
body: <p>I am using this code to play a sound</p>
  
  <pre><code>     final MediaPlayer mp = MediaPlayer.create(this, R.raw.sound);
          mp.setOnCompletionListener(new OnCompletionListener() {
  
              @Override
              public void onCompletion(MediaPlayer mp) {
                  mp.release();
              }
  
          });  
  </code></pre>
  
  <p>It works fine on its own, however there was a problem after I added an animation that extends ImageView, which refreshes(by calling handler.postDelayed) the image resource at an interval about 30ms to create animation. The problem is that when the animation starts, it terminates the the playing of the sound. Here is the code for the Runnable that refreshes the ImageView.</p>
  
  <pre><code> private Runnable runnable = new Runnable () {
  
  
  public void run() {
      String name = "frame_" + frameCount;
      frameCount ++;
      int resId = mContext.getResources().getIdentifier(name, "drawable", mContext.getPackageName());
      imageView.setImageResource(resId);  
      if(frameCount &lt; totalFrameCount) {
          mHandler.postDelayed(runnable, interval);
      }       
  }
  </code></pre>
  
  <p>};</p>
  
  <p>I also tried to use a thread that calls the anmiationView.postInvalidate to do the animation, however it has the same problem. Please help. Thanks</p>
  
  <p><strong>Edit:</strong>
  It looks like the problem is due to WHEN the animation is called. Previously I called it in the onActivityResult of the activity. Looks like this is not the right place to call. Now I put the animation view in a popupWindow and play it there, it works properly. Not sure exactly why.</p>