0
Android處理程序從處理程序消息隊列中刪除先前發送的消息。 請記住我不想使用removeCallbacks
(Runnable
r);Android處理程序刪除發送消息不起作用
發送廣播意圖
- 要發送信息
Intent i = new Intent(my_action);
sendBroadcast(i);
- 要取消任何先前的消息
Intent i = new Intent(my_action);
i.putExtra("a","a");
sendBroadcast(i);
public class TestBroadCast extends BroadcastReceiver {
Handler h = new Handler(){
@Override
public void handleMessage(Message msg) {
// Do my stuff
}
};
Message msg = h.obtainMessage();
@Override
public void onReceive(Context context, Intent intent) {
if ("a".equals(intent.getStringExtra("a"))){
// Handle intent to cancel message
msg.what = 1;
h.removeMessages(1);
} else {
// Handle intent to do my stuff
msg.what = 1;
h.sendMessageDelayed(msg, 10000);
}
}
}
但這removeMessages
後不工作。