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 votes
110 views
Harsh kumar srivastava asked 10-Jan-2018 in Technology by Harsh kumar srivastava

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 votes
Prateek sharma answered 10-Jan-2018 by Prateek sharma

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.