views:

311

answers:

1

What happens on Activity.finish() with an AsyncTask still running in background?

Does it just pop the Activity off the Activity Stack, but wait to destroy the Activity object until the AsyncTask fully completes (since the AsyncTask is an inner class of my Activity)?

Also, would it act any differently if the AsyncTask were a public, non-inner class that held no references to the instance of the Activity?

+2  A: 

I've tried the same thing with the Thread, and my observation is it keeps running the thread.

Karan
Yes, the `AsyncTask` will keep running to completion. It will hold onto a reference to the `Activity`, keeping the `Activity` from being garbage-collected...unless it is a static inner class or fully independent class that has no reference to the `Activity` or anything that points to the `Activity` (e.g., a `View`).
CommonsWare