an interface opened with AsyncTask defines a setting, background action, and an "on done" callback that can update the user interface. this implies that it is intended for operations that have a clearly defined degree, which leads to user feedback.
if you need the current background thread, use Executor to execute the Runnable instance that hosts your current operations. use this with caution, as when your application leaves the foreground, the thread will continue to work. carefully create your Runnable so that it can be interrupted (the run() method can be called to return cleanly).
It is worth noting that AsyncTask simply forces you to clearly define a template for performing an asynchronous operation, and then update the interface. IMHO this is too complicated and makes a lot of assumptions, like a pool of threads with a single or limited size. for example, if one part of your application is blocked in AsyncTask s, do you assume that this will prevent AsyncTask from starting in another part of your application? it will be.
source share