Examples of several methods for Android to update UI in sub threads

This article introduces several methods and examples of Android updating UI in sub threads, which are shared with you as follows:

Method 1: handler and message

① Instantiate a handler and override the handlermessage () method

② Get or create a message in the child thread and send it using the handler object.

Method 2: directly call the activity. Runonuithread (runnable action) method in the child thread

Mode three: Post () method for calling View in sub thread.

Mode four: call View.PostDelayed (Runnabe, long) in child thread.

The long parameter is used to specify the time after which the background process will run

Method 5: Post () method of handler

① Create a handler member variable

(2) mobilize the post () method in child threads.

Method 6: asynctask

Generally, if the UI is simply updated and the situation is not complicated, you can use two or three methods. However, when the situation is complicated, it is recommended to use handler.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>