title: Android: Stop a function listen for a click and the resume
body: <p>I have a function <code>playsounds()</code> which basically plays the same sound file again and again however with a different value of a <code>float</code> called "balance" each time. After each play, I want the function to stop and listen for a user click on a different <code>Button</code>. If there is no click the next play is called.</p>
  
  <p>However, if the user clicks then I want to record that value of balance. My problem is that, once i start the function, there is no way to stop it in between. So even if I click, it gets unnoticed.</p>
  
  <p>Could you help me in the problem ? </p>
  
  <pre><code>public void playsounds() throws InterruptedException
      { 
  
      snd.setBalance(0);
      snd.play(table);
      Thread.sleep(2000);
      tv.setText("Pressed at first call ");
  
      snd.setBalance(0.04f);
      snd.play(table);
      Thread.sleep(2000);
      tv.setText("Pressed at second call ");
  
      snd.setBalance(0.08f);
      snd.play(table);
      Thread.sleep(2000);
      tv.setText("and so on...");
  
      snd.setBalance(0.12f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(0.16f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(1.0f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(1.84f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(1.88f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(1.92f);
      snd.play(table);
      Thread.sleep(2000);
  
      snd.setBalance(1.96f);
      snd.play(table);
      Thread.sleep(2000);    
  
      snd.setBalance(2.0f);
      snd.play(table);
      Thread.sleep(2000);     
  }
  </code></pre>