When can we say an Application is dead(when the application process dies or when all the activities in the process are killed).
Why is it a bad idea to store data in Application's object?
EDIT
Suppose I have a WhatIsYourNameActivity that asks for the user's name and stores that in MyApplication which extends Application. I have another WelcomeActivity which fetches that name from the Application's object. If the user leaves the app(using home button) and android silently kills the app to reclaim some memory, the app then crashes with a null pointer(because the Application object is new) when opened again. Why doesn't a new object of WhatIsYourNameActivity is created?Why is onCreate() method not called() for WhatIsYourNameActivity?(this activity was also killed by the Android. Wasn't it? or killing the app has some other meaning?) What actually happens when the app is killed and started again?
-
1.) when the process dies, it surely the app is dead. 2.) (what data?)Enzokie– Enzokie2017-01-16 12:44:40 +00:00Commented Jan 16, 2017 at 12:44
Add a comment
|
1 Answer
When the process is dead. Because you can have running services or other Thread's which still will works even if all Activities are dead.
Because the Android could kill your app at any time (for example in case if user open other app and that app will allocate all memory) and then restart it again (when the user open your app again). In this case you'll lost all data in Application's object.
You can get more details here - https://developer.android.com/guide/topics/processes/process-lifecycle.html