In my Application I have created a dialog on a button click and started handler on dialog creation now I want to remove handler's callbacks after dialog dismissed and on activity so I have created a handler on oncreate method of activity which continously checks for flag that I set true when dialog dismisses and when flag become true handler's callback should be removed but handler's callbacks are not removed.
final Handler handler_Alerts = new Handler();
Runnable r_Alerts = new Runnable() {
public void run() {
if(Flag){
handler1.removeCallbacks(rhandler1);
}
Toast.makeText(getApplicationContext(), "In Handler", Toast.LENGTH_SHORT).show();
handler_Alerts.postDelayed(this, 1000);
}
};
handler_Alerts.postDelayed(r_Alerts, 1000);