Today I saw a Runonuithread () method used to update the UI, it feels amazing!!
Method One: The handler mechanism does not say.
Method Two: Use Activity.runonuithread (Runnable) to create the code that updates the UI in Runnable, and then pass the Runnable object to Activity.runonuithread when the UI needs to be updated ( Runnable). This way, the runnable can be called in the UI program. If the current thread is the UI thread, then the action is performed immediately. If the current thread is not the UI thread, the action is the UI thread that publishes to the event queue
FusionField.currentActivity.runOnUiThread (new Runnable () { publicvoid Run () { "Update My UI", Toast.length_long). Show (); } });
Public final void Runonuithread (Runnable action) Added in API Level 1
Runs the specified action on the UI thread. If the current thread was the UI thread, then the action is executed immediately. If the current thread was not the UI thread, the action was posted to the event queue of the UI thread.
If the current thread is the main UI thread, execute the runnable code directly, otherwise runnable post to the message queue of the UI threads. -- Just look at the code implementation.
Parameters
Action the action to run on the UI thread
Public Final void Runonuithread (Runnable action) { if (Thread.CurrentThread ()! = Muithread) { Mhandler.post (action); // The runnable post to the message queue is handled by the internal Mhandler, which is actually the handler process . Else { action.run (); // is already running directly on the UI thread. } }
Reference Address:
Http://www.android100.org/html/201406/07/20384.html
http://blog.csdn.net/annkie/article/details/8496219
Two ways to update the UI for Android--handler and Runonuithread ()