1. They say that the "flow" stops immediately after you leave the application (for example, the "Home" button)?
A Thread must be destroyed when the Thread that was launched is destroyed. So, if you run Thread in an Activity , then it should be destroyed when this Activity is destroyed or transferred to Service . For example, you can start music in Thread and update songs there, but if you want it to continue playing when Activity been destroyed, it should be moved to Service
2. If threads are baked in Java, why does android have AsyncTasks?
An AsyncTask allows AsyncTask to run the background and easily update the UI before, during and after the background work is done using any built-in methods except doInBackground() , because this is the only one that does not work on UI Thread
3. Does this basically mean that almost every service will basically have a thread created inside it?
Not necessarily, but you can create a Thread inside it.
4. Is AsyncTask running inside the service incorrectly?
No. Can you do this.
AsyncTask is a great way to do background work. Its methods greatly simplify updating the UI . But you need to read the documentation carefully (maybe even a few times) to make sure you fully understand how to use them. In addition, remember that they are intended for short-term operations, so they can be useful for downloading network data, but should not be used for things that last more than a few seconds (according to the documents).
source share