In an Android app, how long does the application object live? If I have an application and all activities and services is closed and destroyed - does the application object still lives?
3 Answers
In an Android app, how long does the application object live?
It is created after any ContentProviders
when your process is started, and it remains around until your process is terminated.
If I have an application and all activities and services is closed and destroyed - does the application object still lives?
It will "live" as long as your process lives. That may be anywhere from milliseconds to days, depending on what else is going on with the device. Hence, only use a custom Application
object (or, better yet, ordinary Java singletons) for caching. Any data that needs to survive process termination should be stored somewhere persistent.

- 986,068
- 189
- 2,389
- 2,491
-
Thank you. This means that a thread created in the application object continues to run in the background even if all activities are destroyed? – Erik Z Mar 03 '14 at 14:28
-
@ErikZ: Yes. Leaking a thread this way is considered bad form. – CommonsWare Mar 03 '14 at 14:51
-
ya... and to make sure all threads are closed.. we flush all cashes... and then from native code (c++, via jni) call _exit(0); :)) – Marcel Tricolici Mar 03 '14 at 16:06
Application alive until its any one component is alive. Now as per priority service has least priority in getting destroyed. Rest of the components will get destroyed as the device run out of memory.But android keep the reference of application for future launch even after service is killed.

- 3,864
- 2
- 17
- 35