Issue
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);
Solution
There is no way to check if it has a particula runnable. You can call
handler_Alerts.removeCallbacks(r_Alerts);
to remove any instance of r_Alerts inside the Handler queue, or
handler_Alerts.removeCallbacks(null);
to remove all the runnable in its queue
Answered By - Blackbelt
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.