当前位置:网站首页>General operations of asynctask

General operations of asynctask

2022-06-26 03:36:00 kingsley1212

AsyncTask It's a lightweight asynchronous task class , It can always perform background tasks in the thread pool , Then the execution progress and final results are passed to the main thread and are always updated in the main thread UI
2) Inherit AsyncTask Functions that can be implemented

  1. onPreExecute():( Running on the UI In the thread ) ( Non essential method , You don't have to implement )

Called before the task is executed by the thread pool , Usually used to do some preparatory operations , For example, before the download file task is executed , Display a progress bar in this method .

2.doInBackground(Params… params):( Running in child threads )( This function is an abstract function and must be implemented )

Called when the task is executed by the thread pool , Time consuming operations can be handled in this method , Such as downloading files and so on .

3.onProgressUpdate(Progress… values) ( Running on the UI In the thread ) ( Non essential method , You don't have to implement )

This function is used to execute tasks in the thread pool Running state , Call back to UI The progress of the main thread , Such as uploading or downloading progress .

4.onPostExecute(Result result)( Running on the UI In the thread ) ( Non essential method , You don't have to implement )

This function represents that the execution of the task in the thread pool has ended , Call back to UI The result of the main thread . For example, download results .

See this article in detail

原网站

版权声明
本文为[kingsley1212]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180547453178.html