Android – should or should not asynctask be used for long-running operations?

See English answers > Android asynctask for long running operations 4. I'm confused about the content of asynctask. On the one hand, the Android document states that "asynctasks should be used for short operations (a few seconds at the most.)". The document does not explain why this is the case

On the other hand, I've read at least one article that explicitly or implicitly suggests that asynctasks is used for long runs, such as one

Can any Android guru give a more convincing reason why or why not use asynctask for long-running? Or point out the document explaining this. I have been unable to find the answer

Ah, others asked @ L_ 419_ 3@. Let me see if the answer makes sense to me

resolvent:

The interface exposed by asynctask defines a setting, a background operation, and an "on done" callback that can update the UI. This means that it is intended to be used for operations with clearly defined ends, so as to generate feedback to users

If you need an ongoing background thread, please use the executor to execute the runnable instance that hosts the ongoing operation. However, please use it with caution, because when your application leaves the foreground, the thread will continue to run. Carefully make your runnable so that it can be aborted (you can make the run () method return cleanly)

It is worth noting that asynctask will only force you to enter a well-defined mode to perform asynchronous operations and then update the UI. With all due respect, it is too complex and makes many assumptions, such as a single or finite thread pool. For example, if a part of your application is blocked in asynctasks, Do you think it will prevent asynctask from running in another part of your application? It will

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
分享
二维码
< <上一篇
下一篇>>