Currently, Android does not support creating and calling a View in a child thread. If we want to update the sub-thread content and report the results to the main thread in a timely manner, what should we do?
Handler can be created in the main thread. In this way, the thread results can be notified to the main thread by sending a message, and then the View control is updated in time in the main thread.
Handler usage:
MHandler = new Handler (){
@ Override
Public void handleMessage (Message msg ){
Super. handleMessage (msg );
Switch (msg. what ){
Case xxxxxx:
UpdateLotteryInfo ();
Break;
Default:
Break;
}
}
};
When sending a message, you can: mHandler. sendEmptyMessage (xxxxx );
If the content is added, you can: mHandler. obtainMessage (MessageName, MessageContent). sendToTarget ();
In the handleMessage method, msg. obj. toString () can be used to obtain the Message content.
There are other ways to send messages, which can be checked by yourself