Http://www.cnblogs.com/shangdahao/archive/2013/05/19/3069092.html
Android updates the UI thread in other threads
Method 1: activity. runonuithread (runnable)
(Experience: This is the best practice. Wherever you want to refresh the page,
Activity. runonuithread (New runnable ()
{Public void run () {update UI }}
);
Method 2: The subthread calls handler's sendmessage (Message) to send events.
Mhandler = new handler () {@ override public void handlemessage (Message MSG) {// operation interface mytext. settext (information from the network); super. handlemessage (MSG) ;}}; public class mythread extends thread {public void run () {// time-consuming operation loadnetwork (); message MSG = new message (); mhandler. sendmessage (MSG); // send a message to handler ,}}
Method 3: view. Post (runnable)
Public void onclick (view v) {New thread (New runnable () {public void run () {// loadnetwork (); mytext. (new runnable () {mytext. settext (information from the network );});}}). start ();}
Method 4: asynctask
// Execute new downloadimagetask(cmd.exe cute ("www.91dota.com") in the UI thread; private class downloadimagetask extends asynctask {protected string doinbackground (string... URL) {return loaddataformnetwork (URL [0]); // time-consuming operation in the background} protected void onpostexecute (string result) {mytext. settext (result); // get the information from the network to refresh the page }}