I'm new to Android, and i'm having some troubles with savedInstanceState and managing the lifecycle.
http://developer.android.com/guide/topics/fundamentals/activities.html#Lifecycle I read the article about lifecycle, but I don't really know WHEN the process is killed, and my nice savedInstanceSate will be used ! I can press "HOME", but it only launches "onPause" then "onResume" I think.
If I go to Menu->Settings->Application->Manage Application->My application name->Force Stop, it is still seen as a running app, but when I relaunch it, I go back to the "first activity". So it is like closing the application, it's not "Killing the process" as I would like, if I understand well.
So here are my questions :
1)How can I be sure my process have been killed (so my app will use the savedIntanceState when restarted) ?
2)How can I force the process to be killed, to test if my savedInstanceState are well programmed ?
3)When after having been "killed", the app is restarted and the "onCreate" is called (with a savedInstanceState!=null that time), can I still acces to the Intent Extra informations I gave when I called the Activity, or the infomations of the Intent were deleted when the process is killed ? Said differently, must I include in my saveInstanceState a copy of what开发者_JAVA技巧 was stored in the Intent Extra ?
I hope I'm clear enough ;)
1) All you need to worry about is overriding your Activity's onSaveInstanceState()
. Android will call that before it kills your process.
2) You need to setup an Android test project. Then, create a test which extends ActivityInstrumentationTestCase2
, and you can get an Instrumentation
object by calling `getInstrumentation(). From there, you can call Instrumentation.callActivityOnCreate and pass a Bundle object to use for testing.
3) I am pretty sure that you will have store the extras in the savedInstanceState bundle.
精彩评论