Answer the question
In order to leave comments, you need to log in
Why do messages keep coming to the destroyed Handler?
There is Messenger and Handler, which receives messages.
private class IncomingHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
}
}
private IncomingHandler incomingHandler = new IncomingHandler();
private Messenger mMessenger = new Messenger(incomingHandler);
mMessenger = null;
incomingHandler.removeCallbacksAndMessages(null);
incomingHandler = null;
Answer the question
In order to leave comments, you need to log in
Handlers are not tied to the life cycle of services, incl. and on bind/unbind. In the docks they write that "Remove any pending posts of callbacks and sent messages". Nothing is said about the future.
I untie him from the calbacks, destroy him and the Messenger.Resetting links to Messenger and Handler is, of course, not deleting objects. Objects continue to live perfectly, they receive messages, etc. Another thing is that you have some troubles with the life cycle of the service - after all clients have unbinded from it (unbindService), it should end and not send anything else.
mMessenger = null;
incomingHandler.removeCallbacksAndMessages(null);
incomingHandler = null;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question