android - state of AsyncTask when the activity gets destroyed -


in main activity have asynctask running in postexecute() updates listview. before postexecute() gets called if activity gets destroyed due reason state of aynctask. onpostexecute() ui updations throw exception.

one way thought cancel aynctask in ondestory(). if asynctask in postexecute when on destroy gets called how handle it.

but if asynctask in postexecute when on destroy gets called how handle it.

this case cannot happen, because both methods called on ui thread, meaning 1 finished before other called.

when ui no longer available (in ondestroy), cancel asynctask.

in onpostexecute can check cancel status of asynctask. can check isfinishing on activity.


Comments