According to the following understanding, handler has a certain relationship with the ui thread, because the update interface can only be in all the update interfaces in the main thread, and the update interface can be in the handleMessage that receives messages. port (new Runnable) in the Custom thread and then execute the post method to notify the main thread to update this interface
The following is a reference:
Android threads are single-threaded. Therefore, Handler is used to update the UI:
Private Handler splashHandler = new Handler (){
Public void handleMessage (Message msg ){
Switch (msg. what ){
Case OVER:
ProgressDialog. dismiss ();
Break;
Default:
Break;
}
Super. handleMessage (msg );
}
}. After a thread is running, a notification can be sent to Hanler to notify 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); Update the UI directly in Runnable, because Runnable is running in the main thread of the UI.
Android thread controls UI Update (Handler, post (), postDelayed (), postAtTime)