I have checked the official Android documentation/guide for Looper, Handler and MessageQueue . But I couldn’t get it. I am new to android, and got very confused with these concepts.
I have checked the official Android documentation/guide for Looper , Handler and MessageQueue .
Share
A
Looperis a message handling loop: it reads and processes items from aMessageQueue. TheLooperclass is usually used in conjunction with aHandlerThread(a subclass ofThread).A
Handleris a utility class that facilitates interacting with aLooper—mainly by posting messages andRunnableobjects to the thread’sMessageQueue. When aHandleris created, it is bound to a specificLooper(and associated thread and message queue).In typical usage, you create and start a
HandlerThread, then create aHandlerobject (or objects) by which other threads can interact with theHandlerThreadinstance. TheHandlermust be created while running on theHandlerThread, although once created there is no restriction on what threads can use theHandler‘s scheduling methods (post(Runnable), etc.)The main thread (a.k.a. UI thread) in an Android application is set up as a handler thread before your application instance is created.
Aside from the class docs, there’s a nice discussion of all of this here.
P.S. All the classes mentioned above are in the package
android.os.