All what Mark said + be very careful on how the UI gets updated. If you,
like most others, are using an inner class for AsyncTask then the outer
instance is no longer the visible instance when your app goes away or even
an orientation changes. My 2c., AsyncTask has a noble intention but a very
unforgiving implementation given the app lifecycle. The easiest place to use
an AsyncTask is where you want something computed as long as the app is
visible, i.e. you start it off in onResume and cancel it in onPause. Any
thing else and you will be doing a lot of gymnastics and should be really
looking at alternatives.
On Mon, Dec 13, 2010 at 7:17 AM, Mark Murphy mmur...@commonsware.comwrote:
On Mon, Dec 13, 2010 at 7:13 AM, umakantpatil umakantpat...@gmail.com
wrote:
I'm just confused about the lifecycle of activity and AsyncTask.
I have an activity which opens new AsyncTask. Now if finish() that
activity,
will be background task also get closed ?
No.
Or will it be still going ?
Yes.
If going on then how long it will be going, till my code exceute or till
the
app gets exited ?
The background thread of the AsyncTask should keep running until
doInBackground() completes or the process is terminated.
However, this is not a good thing. If you need to have background
threads live even after an activity is finished, please have those
threads be managed by a Service (perhaps even an IntentService).
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
_The Busy Coder's Guide to *Advanced* Android Development_ Version 1.9
Available!
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en