7

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);
4

5 に答える 5

5

実行可能な粒子があるかどうかを確認する方法はありません。あなたは呼び出すことができます

handler_Alerts.removeCallbacks(r_Alerts); 

Handler キュー内の r_Alerts のインスタンスを削除する、または

handler_Alerts.removeCallbacks(null);

キュー内のすべてのランナブルを削除する

于 2013-06-05T09:57:19.933 に答える