I was just seeing the documentation of three methods which can be used to execute a piece of code in the UI thread while we are working in a worker thread. The methods are:
1. public final void runOnUIThread(Runnable action) - Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread
2. public boolean post(Runnable action) - Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.
3. public boolean postDelayed(Runnable action, long delayMillis) - Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.
The first one posts the Runnable to the event queue of the UI thread, while the other two add the Runnable to the message queue. Please tell me the difference between the two?
My web search tell me that an event queue is simply a queue of events waiting to be executed by the thread. I am not clear about the message queue. MessageQueue is some class as well, is this related to that?
Thank you in advance.
No comments:
Post a Comment