title: Runnable wont stop
body: <p>I am making a game where if the player intersects with bear, it will stop the runnable thread. but somehow it wont stop at all. So when player intersects with bear, the player should be dead.  the dead loop is called but it will not stop the runnable. 
  I made the runnable loop as below  </p>
  
  <pre><code>protected void movement() {
  
      final int delay = 5;
      speed = 20;
  
      r = new Runnable() {
  
          @Override
          public void run() {
  
              if (countscore % 300 == 0) {
                  speed = speed + 5;
  
              }
  
              bear1.setY(bear1.getY() + speed);
              bear2.setY(bear2.getY() + speed);
              reframeroad();
  
              if ((animImageView.getX() &lt; bear1.getX() + 50 &amp;&amp; animImageView.getX() &gt; bear1.getX() - 50) ||
                      (animImageView.getX() &gt; bear2.getX() &amp;&amp; animImageView.getX() &lt; bear2.getX())) {
                  System.out.println("goes inside getx intersects x ");
                  dead();
  
              }
  
              if (Rect.intersects(thiefRect, bear1Rect) || Rect.intersects(thiefRect, bear2Rect)) {
                  System.out.println(" goes inside intersects if loop ");
  
                  dead();  // this gets called
              }
  
              h.postDelayed(this, delay);
          }
      }; h.postDelayed(r, speed);
  }
  
  public void dead(){
      System.out.println("before callbacks null");
      h.removeCallbacksAndMessages(r);
  
      System.out.println("goes inside dead function");
  
      bear1.setVisibility(View.INVISIBLE);
      bear2.setVisibility(View.INVISIBLE);
      animImageView.setVisibility(View.INVISIBLE);
  
  
     scorebox.setText(countscore + "");
      scorebox.setVisibility(View.VISIBLE);
      score.setVisibility(View.VISIBLE);
  
      retry.setVisibility(View.VISIBLE);
  
      retry.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(GameActivity.this, GameActivity.class));
              finish();
          }
      });
  }
  </code></pre>
  
  <p>I tried a lot but I will still call back on every 5ms. </p>
  
  <p>My console loops like this every time </p>
  
  <pre><code>&gt; 04-19 10:36:40.687 14923-14923/: goes inside getx intersects x  
  &gt; 04-19 10:36:40.687 14923-14923/: before callbacks null 
  &gt; 04-19 10:36:40.687 14923-14923/: goes inside dead function 
  &gt; 04-19 10:36:40.747 14923-14923/: goes inside getx intersects x  
  &gt; 04-19 10:36:40.747 14923-14923/: before callbacks null 
  &gt; 04-19 10:36:40.747 14923-14923/:goes inside dead function 
  &gt; 04-19 10:36:40.807 14923-14923/: goes inside getx intersects x  
  &gt; 04-19 10:36:40.807 14923-14923/: before callbacks null 
  &gt; 04-19 10:36:40.807 14923-14923/: goes inside dead function 
  &gt; 04-19 10:36:40.868 14923-14923/: goes inside getx intersects x  
  &gt; 04-19 10:36:40.869 14923-14923/: before callbacks null 
  &gt; 04-19 10:36:40.869 14923-14923/: goes inside dead function
  </code></pre>
  
  <p>even the my score keeps on increasing after the dead function is called</p>
  
  <pre><code>scorebox.setText(countscore + "");
  </code></pre>
  
  <p>How do i stop this runnable thread?</p>