SavedInstanceState is always null in fragment

后端 未结 5 1872
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 04:08

I have a fragment attached to the activity using XML (and setContentView() in activity). A have a problem because I have very dynamic views in my fragment, so when orientati

5条回答
  •  臣服心动
    2020-11-30 04:41

    First you should put your data, then call super.onSaveInstanceState(outState);

    public void onSaveInstanceState(Bundle outState) {
    
        outState.putBoolean("restore", true);
        outState.putInt("nAndroids", 2);
        super.onSaveInstanceState(outState);
    }
    

    And be sure that activity has not nohistory property in AndroidManifest.xml or set it to false.

            
    

提交回复
热议问题