title: How to cancel the timer and renew the same timer?
body: <p>I am creating an app that vibrate and beep every 30 sec and when I log out the vibrate and beep must be cancelled and when I log in the vibrate and beep should resume. </p>
  
  <p>NOTE: it must vibrate and beep for every 30 sec until I log out  </p>
  
  <p>In my app I am using <code>TimerTask</code> for this implementation</p>
  
  <p>this is the code for vibrate and beep using <code>TimerTask</code></p>
  
  <pre><code>static TimerTask Task;
  final static Handler handler = new Handler();
  static Timer t = new Timer();
  
  public static void vib() {
  
      Task = new TimerTask() {
          public void run() {
              handler.post(new Runnable() {
                  public void run() {
                      Vibrator vibrator = (Vibrator) ApplicationUtils.getContext().getSystemService(Context.VIBRATOR_SERVICE);
                      vibrator.vibrate(3000);
                      playSound();
                      Log.d("TIMER", "Timer set on");
                  }
              });
          }
      };
      t.schedule(Task, 0, 30000); 
  }
  </code></pre>
  
  <p>This is the code I'm using in logout section</p>
  
  <pre><code>public void stopvib() {
      if (Task != null) {
      //  Log.d("TIMER", "timer canceled");
          t.cancel();
          Task.cancel();
      }
  }
  </code></pre>
  
  <p>Note: I also removed the <code>Task.cancel();</code> but still I am getting same error </p>
  
  <p>My vibrate working fine before logout and again login I am geting error </p>
  
  <pre><code>java.lang.IllegalStateException: Timer was cancelled
      at java.util.Timer.scheduleImpl(Timer.java:562)
      at java.util.Timer.schedule(Timer.java:481)
      at com.vib(AlertListActivity.java:724)
  </code></pre>
  
  <p>can any one help me with this coding. Where did I go wrong? </p>