-
The following understanding is that handler and the UI thread have a certain association can be because the update interface can only be in the main thread all the update interface in the handlemessage of receiving the message there is also the update interface can be Handler.port (new Runnable) In a custom thread, then execute the Post method to notify the main thread to update the interface
Here are the references:
The Android thread is single-threaded. So update the UI to use handler:
private Handler splashhandler = new Handler () {
public void Handlemessage ( Message msg) {
switch (msg.what) {
case-over:
Progressdialog.dismiss ();
break;
Default:
Break
}
super.handlemessage (msg);
}
}; When a thread finishes running, it can send a notification to Hanler, notifying the main thread to update the UI:
New Thread () {public void run () {
Initlist ();
Message m = splashhandler.obtainmessage (over);
Splashhandler.sendmessage (m);
Splashhandler.post (R);
Splashhandler.postdelayed (R, Delaymillis);
Splashhandler.postattime (R, Uptimemillis);
}}.start (); can also be used directly:
Splashhandler.post (New Runnable () {
public void Run () {
Progressdialog.dismiss ();
}
});
Splashhandler.postdelayed (R, Delaymillis);
Splashhandler.postattime (R, Uptimemillis); Updates the UI directly in Runnable because the Runnable at this point is running in the main thread where the UI is located.
Android Threading Controls UI updates (Handler, post (), postdelayed (), Postattime)
Android Threading Controls UI updates (Handler, post (), postdelayed (), Postattime)