title: TimerTask cancel / restart
body: <p>In my app I use <code>TimerTask</code> to repeat an action every x seconds, but now I want to stop the <code>TimerTask</code> with a button and run it again by pressing another. Here is what I have so far:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  Timer Tempogatto = new Timer();
  timerTempogatto timerTempogatto = new timerTempogatto();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  
  final TextView  start = (TextView)findViewById(R.id.start);
  start.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
  // TODO Auto-generated method stub
  if(event.getAction() == MotionEvent.ACTION_DOWN){
  
      Tempogatto.schedule(timerTempogatto, 0, 20000);         
  
  }
  
      return true;
  }
  
  });  
  
  final TextView  stop = (TextView)findViewById(R.id.stop);
  stop.setOnTouchListener(new OnTouchListener() {
  @Override
  public boolean onTouch(View v, MotionEvent event) {
  // TODO Auto-generated method stub
  if(event.getAction() == MotionEvent.ACTION_DOWN){
  
      Tempogatto.cancel                       
  
   }  
  return true;
  }
  
  });  
  
  
  
  
  
  
  (.....)
  
      private class timerTempogatto extends TimerTask {
          @Override
          public void run() {
              runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
  
                      //code i want to repeat every 20 second
  
  
  
                  }
              });
          }
      }
  </code></pre>
  
  <p>naturally  when I click stop <code>TextView</code> and then the Start <code>TextView</code> for restart <code>TimerTask</code>, it give me </p>
  
  <pre><code>java.lang.IllegalStateException: Timer was canceled 
  </code></pre>