Well even an AsyncTask that runs for only a few seconds will have time to leak many Activity instances if you quickly do many configuration- changes. Although in that case onDestroy gets called so you could unregister the Activity from the task there.
Anyway, I don't want to create another service just for this - and it doesn't really solve anything since either the task has a reference to an activity or it doesn't. I tried using the Application context in the PendingIntent and it seems to work - I think I'll do it that way... On Jul 24, 3:10 pm, Joseph Earl <joseph.w.e...@gmail.com> wrote: > Yup. Use a service for long running background tasks that do not > require an Activity to be present. > Threads started by an Activity are killed anyway when your Activity is > destroyed (or at least that's how it seems to me). > You can bind to your service from your Activity to control it. > > On Jul 24, 1:28 pm, sasq <jonas.minnb...@gmail.com> wrote: > > > > > I have an AsyncTask that scans the file system and publishes progress > > through Notifications. To do this I need a reference to the current > > Activity in the AsyncTask. > > > I also don't want to kill the task when the activity is destroyed. How > > do I avoid leaking the activity and everything it references on each > > configuration change? > > > One possibility is to remove the reference in OnPause() to be sure it > > is gone when the Activity is destroyed, but that would mean > > notifications stops coming as soon as you leave the activity which is > > no good. > > > Isn't there a recommended way of dealing with AsyncTasks in this way? -- 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