0
  1. When can we say an Application is dead(when the application process dies or when all the activities in the process are killed).

  2. Why is it a bad idea to store data in Application's object?

    EDIT

  3. 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
  • 1.) when the process dies, it surely the app is dead. 2.) (what data?) Commented Jan 16, 2017 at 12:44

1 Answer 1

4
  1. 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.

  2. 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

Sign up to request clarification or add additional context in comments.

2 Comments

when you are saying "Android could kill your app at any time". Does that mean killing my app process?
Yes, I mean process

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.