How do I call getLooper () on the main thread?
On Android, Main Thread and HandlerThread
Looper and MessageQueue are set by default. I can call getLooper () on the handlerThread object, but why not include the main theme?
HandlerThread ht = new HandlerThread();
Looper htLooper = ht.getLooper(); // Works fine
Thread mainThread = Looper.getMainLooper().getThread();
Looper mainLooper = mainThread.getLooper(); // getLooper() doesn't compile.
In a real-world scenario, you should never use getLooper () on mainThread; we can just call Looper.getMainLooper()
. I just would like to know why this is not working.
I understand this in terms of Java, what it Looper.getMainLooper().getThread()
returns java.lang.Thread
, and the Thread class doesn't have a getLooper () method; but the main Android thread. How can I access the main topic HandlerThread
?
source to share