簡體   English   中英

Android PreferenceActivity:onSaveInstanceState之后,onCreate方法中的bundle為空

[英]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消息。

我知道我可以使用onStoponResume方法,但是我認為這不是正確的方法。

我通過使用的onResume和onStop方法解決了這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM