When is InstanceState saved really used?

I am new to Android and am having problems with savedInstanceState and lifecycle management.

http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle I read an article on the life cycle, but I really don't know WHEN the process is killed and my good saveInstanceSate will be used! I can press "HOME", but it only starts "onPause" and then "onResume". I think so.

If I go to Menu-> Settings-> Application-> Manage Application-> My application name-> Force Stop, it is still regarded as a running application, but when I restart it, I return to "first Events". So it’s like closing the application, it’s not a “Killing process”, as I would like if I understand well.

So here are my questions:

1) How can I be sure that my process was killed (so my application will use saveIntanceState when it restarts)?

2) How can I get a process to be killed to check if my savedInstanceState file is well programmed?

3) When after the “killed” application restarts and “onCreate” is called (with the saved value InstanceState! = Null), can I access the additional information that I gave when I called Activity or intent information was deleted when the process was killed? Speaking differently, should I include in my saveInstanceState a copy of what was saved in Intent Extra?

Hope I'm clear enough;)

+4
source share
1 answer

1) Everything you need to worry about redefines your onSaveInstanceState() activity. Android will call this before it kills your process.

2) You need to set up an Android testing project . Then create a test that extends ActivityInstrumentationTestCase2 , and you can get the Instrumentation object by calling `getInstrumentation (). From there, you can call Instrumentation.callActivityOnCreate and pass the Bundle object for use for testing.

3) I am sure that you will store additional functions in the savedInstanceState package.

+1
source

Source: https://habr.com/ru/post/1369412/


All Articles