質問

The documentation on onSaveInstanceState() states:

If the method is called, it is always called before onStop() and possibly before onPause().

But, I notice, consistently, from log messages that onPause() is ALWAYS CALLED BEFORE onSaveInstanceState(). I had put log messages in these two methods. Please help me understand in what circumstances does onSaveInstanceState() is called before onPause().

Environment: Android v4.0 (API 14) + Eclipse v3.7.1 - Indigo.

役に立ちましたか?

解決

You can read about that here.

In a nutshell you can't never know about time when onSaveInstanceState will be run.

他のヒント

Please help me understand in what circumstances does onSaveInstanceState() is called before onPause()

There is a difference in the Activity lifecycle between the pre-HONEYCOMB and the other platforms (since HONEYCOMB onwards):

API level >= 11: when onPause() is called, the process is in a safe state, it can't be killed.

API level < 11 : when onPause() is called, the process that hosts the Activity becomes killable. It means that the system can kill the process, that contains the activity, without executing any other line of code. So if this happens the onSaveInstanceState() may never be called. In order to avoid this, the system should call onSaveInstanceState() before onPause(), otherwise you will not able to save the user state.

onSaveInstanceState() is nice, but only guaranted callback is onPause(), called when your activity loses focus. So, save your state there

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top