![](/img/trans.png)
[英]Is the method onSaveInstanceState(Bundle) called after onPause()?
[英]Android PreferenceActivity : Bundle is null in onCreate method after the onSaveInstanceState
我正在使用PreferenceActivity,並且想在設備旋轉時恢復其狀態。
我要保存狀態onSaveInstanceState方法:
@Override
protected void onSaveInstanceState(Bundle icicle) {
super.onSaveInstanceState(icicle);
icicle.putString("LevelsValue", levelPref.getSummary().toString());
}
並在onCreate方法中:
if (savedInstanceState!=null)
Toast.makeText(getApplicationContext(), "savedInstanceState is not null", Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(), "savedInstanceState is null", Toast.LENGTH_SHORT).show();
而且我總是收到savedInstanceState is null
消息。
我知道我可以使用onStop
和onResume
方法,但是我認為這不是正確的方法。
我通過使用的onResume和onStop方法解決了這個問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.