What is the relationship between the life cycle of an AsyncTask and an Activity? What problems can this result in? How can these problems be avoided?

Asked 10-Jan-2018
Viewed 524 times

1

What is the relationship between the life cycle of an AsyncTask and an Activity? What problems can this result in? How can these problems be avoided?


1 Answer


1

an async task works within the activity so the lifecycle does not come together. as async task works continuously for a period of time until it completes the process it is doing. so if the app does any activity which destroys the instance of the activity the app may make an exception because the async task will return an instance to the older activity instance which is destroyed. 

to avoid this exception user must use other option such as service or sync adapter for a long-running service.