I am learning Android app development from Udacity.com by Google engineers and they said,
"It is not a good idea to use 'AsyncTask
' as it is not attached to an activity
life cycle. The virtual machine will hold on to the activity
object as long as the Asynctask
is running, even after Android has called onDestroy( ) method for the activity and expect it to be discarded.
If you rotate your phone, the behavior is to destroy the current activity and instantiate a new one. The naive AsyncTask
implementation now has two threads
trying to do the same update. So it is not the best pattern for a potentially very long running background operation , such as fetching from web services. If you leave the app, the asyncTask
will run as long as as the process is kept alive , but will run at a lower priority, and your process will be the first thing to be killed if the device needs more resources. "
1) If using AsyncTask
is disadvantageous why was it created? What would have been the design philosophy or the cause to create it in spite of having services(or something similar to achieve same kind of functionality)?
2) What are the situations where Asynctask
should be used for betterment compared to Services/similar options available in Android?
3) What are the situations/places Asynctask
should never be used?
Please do not downvote this question. I searched Stackoverflow and I couldn't find a similar question.