Problems------Why if the red Asynctask
Sends an HTTP request to the server, the server returns some data to the user, and then displays the data in the UI
This time there is a phenomenon: because the Android access server must be placed in the sub-thread, and the UI update data must be placed in the main thread, so when the main thread to show the data, encountered some time-consuming operations such as access to the server, database queries and other operations, the main thread will be blocked, The user will see the ANR (the program is not responding). And Asynctask is a good solution to this kind of problem.
How to use Asynctask
Create a class mytask inherit from Asynctask
Implementing the Asynctask Doinbackground () method
This method must be implemented primarily to write asynchronous task main code to perform some time-consuming operations that can call Publishprogress () to update progress information during execution
Onprogressupdate ()
When the Publishprogress () method is called, the progress information is presented to the UI
OnPreExecute () The method is called first when the Execute () method is executed, primarily to make some declarations about some of the UI's Information OnPostExecute () The method is called when the operation of the asynchronous task ends, and is used to update the UI information Execute () method, This method is used to open the execution of an asynchronous task and must be opened in the main thread.
This article is from the "Five Piglets" blog, please be sure to keep this source http://wuxiaozhu.blog.51cto.com/7942143/1764480
Asynchronous tasks in Android-----------Asynctask use