title: Timer Not Stopping In Android
body: <p><strong>THE PROBLEM</strong>
  I am having problems stopping the Timer whilst developing in android.</p>
  
  <p>The timer is already null when it comes to stopping it.</p>
  
  <p>I then move the timer initialisation to outside of a method just like the TimerTask which solves the null problem but still doesn't cancel when <code>timer.cancel();</code> is called upon it.</p>
  
  <p>The code below is an example of the timer already being null when it comes to stopping the recording.</p>
  
  <p><strong>TimerTask</strong></p>
  
  <p>My <code>TimerTask</code> is initialized inside the class but outside of a method and the codes below...</p>
  
  <pre><code>private TimerTask task = new TimerTask() {
      @Override
      public void run() {
        Log.e("TRACK_RECORDING_SERVICE","Timer Running");
      }
    };
  </code></pre>
  
  <p><strong>Timer &amp; Timer Start</strong></p>
  
  <p>I then have a startRecroding method which is called when I want to start the timer...</p>
  
  <pre><code>public void startRecording(){
       timer = new Timer("Message Timer");
       timer.scheduleAtFixedRate(this.task, 0, 1000);
   }
  </code></pre>
  
  <p><strong>Timer Stop</strong></p>
  
  <p>I then call the below method when I want to stop the timer...</p>
  
  <pre><code>public void stopRecording() {
       if (timer != null) {
           timer.cancel();
           timer = null;
       } else {
           Log.e("TRACK_RECORDING_SERVICE","Timer already null.");
       }
   }
  </code></pre>
  
  <p>Any help would be much appreciated.</p>