Handler.removeCallbacks() doesn't remove callback - Why?
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.
精彩评论