Still having trouble ending a thread
<p>I got some answers, and Went ahead and tried the following:</p>

<pre><code>01 import android.app.Activity;
02 import android.media.MediaPlayer;
03 import android.os.Bundle;
04 import android.os.Handler;
05 import android.os.Message;
06 import android.media.MediaPlayer;
07 import android.media.AudioManager;
08 import android.content.Context;
09 import java.lang.Runnable;
10  
11 public class CanvasDrawingActivity extends  Activity   {
12      
13     private static final int FIRE = 0;
14     private int initVolume = 0;
15     private Handler handler;
16     private MyCanvas v;
17     private MediaPlayer mp;
18     private AudioManager am;
19     private MyRunnable r;// this is our custom runnable!
20  
21     @Override
22     public void onCreate(Bundle savedInstanceState) {
23         super.onCreate(savedInstanceState);
24          
25         am = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
26               
27             // this method gets the current volume setting for music
28             initVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
29               
30             // this method sets the volume for music | the 100 is the volume. you can put there either initVolume or whatever value you want
31             am.setStreamVolume(AudioManager.STREAM_MUSIC,100,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
32          
33         mp = MediaPlayer.create(this, R.raw.siren_1);
34          
35         makeHandler();
36         v =new MyCanvas(this);
37         setContentView(v);
38         r = new MyRunnable();// this needs to create a new MyRunnable
39         new Thread(r).start();
40         mp.setLooping(true);
41         mp.start();
42     }
43     private void makeHandler()
44     {
45         handler  = new Handler(){
46  
47             @Override
48             public void handleMessage(Message msg) {
49                 switch(msg.what)
50                 {
51                 case FIRE:
52                 {
53                     v.invalidate();
54                     break;
55                 }
56                 }
57             }
58              
59         };
60          
61     }
62     private class MyRunnable extends Runnable {// you had this in the wrong spot...
63             private boolean doRun = true;
64              
65             @Override
66             public void run(){
67             while(doRun)
68                 handler.sendEmptyMessage(FIRE);
69                 }
70         public void stopThread(){
71             doRun = false;
72         }
73     }
74     protected void onpause() {
75         super.onpause();
76         mp.stop();
77         r.stopThread();
78         finish();
79     }
80     protected void onfinish() {
81         mp.stop();
82         r.stopThread();
83         finish();
84     }
85          
86     }
</code></pre>

<p>I'm getting an error that runnable cannot be the superclass. Specifically that the type runnable cannot be the superclass of MyRunnable; a superclass must be a class.</p>

<p>Then in the onpause and onfinish it gives the error: Te method stopThread is undefined for the type runnable. This happens even when extends is changed to implements. </p>

<p>I also tried:</p>

<pre><code>01 Runnable MyRunnable = new Runnable(){
02        
03          
04         private boolean doRun = true;
05          
06         @Override
07         public void run(){
08             while(doRun)
09                 handler.sendEmptyMessage(FIRE);
10         }
11         public void stopThread(){
12             doRun = false;
13         }
14     }
</code></pre>

<p>I tried also:</p>

<pre><code>private class MyRunnable implements Runnable \\etc
</code></pre>

<p>that clears up the runnable issue but causes my </p>

<pre><code>r = new MyRunnable();
</code></pre>

<p>and</p>

<pre><code>r.stopThread();
</code></pre>

<p>to be errors still which say:
the <code>stopThread is undefined for the type runnable, and Type mismatch cannot convert from CanvasDrawingActivity.MyRunnable to Runnable.</code></p>

<p>Can anyone help me out here. I feel like this is a good option to end the thread, but again, I get some impassable errors...</p>
