Android Handler remove callback

  • Replies:2
ashokk
  • Forum posts: 1

Jun 7, 2013, 9:11:57 AM via Website

In my Application I am using handlers for showing alerts after sometime. I have used postdelayed() method for delay. I want to remove handler's callback
so how to check that handler has callback?

final Handler handler_Alerts = new Handler();
Runnable r_Alerts = new Runnable() {
public void run() {
Toast.makeText(getApplicationContext(), "In Handler", Toast.LENGTH_SHORT).show();
handler_Alerts.postDelayed(this, 1000);
}
};

handler_Alerts.postDelayed(r_Alerts, 1000);

Now I want to remove this handler's callback

Reply
Deactivated Account
  • Forum posts: 442

Jun 8, 2013, 6:04:39 PM via App

The runnable repeats again and again...
So simply add an if statement:
1if(running) {
2handler.post.....
3}
If you want to stop it set running to false :D

Hi, bin 13 Jahre alt :D Erstes Android Spiel "Strategic Labyrinth": http://goo.gl/Q0Wbd

Reply
Deactivated Account
  • Forum posts: 442

Jun 8, 2013, 6:05:16 PM via App

u can also use:

handler.removeCallback(runmable);

Hi, bin 13 Jahre alt :D Erstes Android Spiel "Strategic Labyrinth": http://goo.gl/Q0Wbd

Reply