title: Android Thread interupt when activity destroy does not work
body: <p>I'm new to android developing. I have an activity where I create a thread to load an image and refresh it on imageView. The thread runs an "infinite loop". I want to also stop the thread when the activity is stopped. Below you can see in sample what I have implemented but it throws exception and the thread continues to work or the app crashes. Any suggestions?</p>
  
  <pre><code>public class myActivity extends Activity{
  
     Thread tr;
  
  
     .... onCreate(){
          bla bla bla
  
          tr = new Thread();
          tr.start();
     }
  
     .....onDestroy(){
          tr.interupt();
     }
  
     bla bla bla
  }
  </code></pre>
  
  <p>Sorry for not writing the full code but I'm not home right now where I have the code.
  What should I change to make it stop ok?</p>
  
  <p>I have also tried another trick, where I set a public static boolean  and onDestroy I set it false. </p>
  
  <p>In the thread the "infinite loop" wokrs as : </p>
  
  <pre><code>public static Boolean is = true;
  </code></pre>
  
  <p>in thread:   </p>
  
  <pre><code>while (is == true)....
  </code></pre>
  
  <p>onDestroy:</p>
  
  <pre><code>is = false; 
  </code></pre>
  
  <p>So, with this trick, since the loop will end, will the thread be killed when it has ended it's operations?</p>