Reference to running Thread is null
<p>I can't get a spawned thread to stop:</p>

<p>I'm implementing the vibration-part of the Ringer-class in the regular Android Phone.apk (basically word for word), but after vibrating once (and stopping) correctly, the second time I call <code>startVibration()</code> and subsequently <code>stopVibration()</code>, it <em>doesn't</em> stop the thread (the log prints out that mVibratorThread is null, even though an instance of it is clearly still active, because the phone is vibrating :-)!)...</p>

<pre><code>public volatile boolean mContinueVibrating;
public VibratorThread mVibratorThread;
private static final int VIBRATE_LENGTH = 1000; // ms
private static final int PAUSE_LENGTH = 1000; // ms

public void startVibration(){
    //Start the vibration alarm
    if (mVibratorThread == null) {
        mContinueVibrating = true;
        mVibratorThread = new VibratorThread();
        Log.i(TAG, "Starting vibration...");
        mVibratorThread.start();
    }
}

public void stopVibration(){
    //Stop the vibration alarm
    Log.i(TAG, "Stopping vibration...");
    if (mVibratorThread != null){
        mContinueVibrating = false;
        mVibratorThread = null;
        Log.i(TAG, "Thread wasn't null, but is now set to null...");
    } else {
        Log.i(TAG, "Thread was null...");
    }
}

private class VibratorThread extends Thread {

    public void run() {
        Vibrator mVibrator = (Vibrator) m_context.getSystemService(Context.VIBRATOR_SERVICE); 
        while (mContinueVibrating) {
            mVibrator.vibrate(VIBRATE_LENGTH);
            SystemClock.sleep(VIBRATE_LENGTH + PAUSE_LENGTH);
            Log.i(TAG, "VIBRATING NOW!!" + mContinueVibrating);
        }
    }
}
</code></pre>

<p>I've already tried the method described in <a href="http://stackoverflow.com/questions/680180/where-to-stop-destroy-threads-in-android-service-class">Where to stop/destroy threads in Android Service class?</a></p>

<p>Thanks for your help,<br>
Nick</p>
