java - Android handler handleMessage() method call -
when instantiate handler
object (for example lets using anonymous inner class) in main ui thread.
handler h = new handler () { @override public void handlemessage (message msg) { /* code handle message */ } };
we can pass handler
object reference other thread can post status updates ui thread using reference (h.sendmessage()
).
doubt: have not provided our custom anonymous class reference h
handler
anywhere activity
class or ui thread. in order call overridden method ui thread must have object reference our class. how overridden handlemessage()
called instead of default one?
your handlemessage()
being called looper
. can see here looper calls dispatchmessage on message target handler. , target being assigned this
reference when post message inside handler. flow follows:
you post message on handler, internally creates message object reference handler.
that message put message queue managed main ui thred (in particular case)
when time comes, android removing message queue , using target field - calls handlemesage on it.
also - whats important if dont specify particular looper when creating handler, default looper used thread being instantiated. in case main ui looper.
Comments
Post a Comment