开发者

Handler.removeCallbacks() doesn't remove callback - Why?

开发者 https://www.devze.com 2023-03-28 00:32 出处:网络
Given the following LogCat 开发者_Python百科trace, which shows that Handler.removeCallbacks() is called (via MyListener.cancelTimeout()) clearly before myTask.run():

Given the following LogCat 开发者_Python百科trace, which shows that Handler.removeCallbacks() is called (via MyListener.cancelTimeout()) clearly before myTask.run():

08-12 17:29:13.990: VERBOSE/MyListener.setTimeout(2625): TID: 2625, Handler{460a86e8}, myTask@461cc378
08-12 17:29:14.000: VERBOSE/MyListener.cancelTimeout(2625): TID: 2625, Handler{460a86e8}, myTask@461cc378
08-12 17:29:16.010: VERBOSE/myTask.run(2625): TID: 2625, MyTimeoutTask(handleTimeout())
08-12 17:29:16.010: VERBOSE/MyListener.cancelTimeout(2625): TID: 2625, Handler{460a86e8}, myTask@461cc378
08-12 17:29:16.010: VERBOSE/MyListener.handleTimeout(2625): TID: 2625

What could possibly explain this mystery?

Note the exact timestamps in the log: The same exact Runnable object (myTask@461cc378) is being removeCallbacks()-ed exactly 0.01 seconds after it has been postDelayed(). Then, 2.01 seconds later, it is run()...

What could possibly explain this?

For example, is 0.01 second too short for Android to figure out order?

Any ideas for debugging this would be very much appreciated.


This does work. You haven't given any code to help figure out what you are doing wrong, but you are doing something wrong: removing from the wrong handler, passing the wrong runnable, something.

0

精彩评论

暂无评论...
验证码 换一张
取 消