The problem I've had with AsyncTask is that if the main activity exits and the background task finishes a bit later, the UI that the b/g task wants to update in its PostExecute method no longer exists, and I get a Force Close when it tries to use one of the Views that I'd previously saved. So you might want to do some checking from PostExecute to verify that your views still exist if you need them.
Doug G On Dec 13, 7:17 am, Mark Murphy <mmur...@commonsware.com> wrote: > 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/commonsguyhttp://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.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en