Well, first of all, let's see how the method works Message recycle().
public void recycle() {
if (isInUse()) {
if (gCheckRecycle) {
throw new IllegalStateException("This message cannot be recycled because it "
+ "is still in use.");
}
return;
}
recycleUnchecked();
}
So, you get IllegalStateExceptionif it is used
isInUse() just checks the flag and looks like this:
boolean isInUse() {
return ((flags & FLAG_IN_USE) == FLAG_IN_USE);
}
And when we try to read about this flag, we see a description:
If the set message is used.
, , , . , , , .
, .
,
recycleUnchecked() , . , ! :
, .
MessageQueue Looper .
, . , , :
handler.removeMessages(int what)
, , :
msg.recycle();
try {
msg.recycle(); //it can work in some situations
} catch (IllegalStateException e) {
workerHandler.removeMessages(msg.what); //if recycle doesnt work we do it manually
}