Android- How to detect in a resume that my application has been killed by a VM?

In my application, when the user presses the HOME button and returns to the application after some time, my application provides NullPointerExceptions in different places and actions. I know that my application kills the OS to free some resources. Now I want that when the user returns to the application and the application again, was previously killed, then how can I find out that my application has been killed so that I can restart different resources?

+4
source share
3 answers

When onCreate (Bundle savedInstanceState) , make sure savedInstanceState not null. As indicated onCreate :

savedInstanceState If the activity is reinitialized after it was previously closed, then this package contains the data that it most recently delivered to onSaveInstanceState (Bundle). Note: Otherwise, it is null.

See also onSaveInstanceState () , which is not part of the normal life cycle, but is called before the action is killed.

Note: if the user does A ----> B ----> C -back → B ----> C, then the second time C is created, the transferred set will be null , since this is a new instance that has not been recreated after that how they killed him.

+6
source

Basically: look at the picture on this page: http://developer.android.com/reference/android/app/Activity.html

enter image description here

various functions that are called in different situations are onCreate , onStart and onResume .

+3
source

My suggestion would be: implement your own Application , and if onCreate() is onCreate() , the application was killed in the background

0
source

All Articles