onSaveInstanceState is not saving my values ( onCreate input Bundle is always null )

前端 未结 6 1483
轻奢々
轻奢々 2020-12-10 12:19

Saving bundle (activity A):

@Override
protected void onSaveInstanceState(Bundle outState) {
    outState.putString(\"test\", \"value\");
    super.onSaveInst         


        
6条回答
  •  生来不讨喜
    2020-12-10 12:59

    Unless your app is running on Lollipop (API21) version of Android or newer, your

    public void onSaveInstanceState (Bundle outState, PersistableBundle outPersistentState);
    

    will NOT be called as it simply does not exist on earlier versions of the platform than 21. To support pre API 21 devices you must, instead of the above, override the following method:

    public void onSaveInstanceState (Bundle outState);
    

    This will work on API 21+ as well, so you do not need to override both methods, of course (unless you know you need to deal with PersistableBundle the new one offers).

    (Copied because it worked for me) Source: onSaveInstanceState is not getting called after screen rotation

提交回复
热议问题