Android: onSaveInstanceState in Back button

后端 未结 2 1767
离开以前
离开以前 2021-01-19 18:02

I am developing an application in which i am overriding the back button. I created a check box. On click of which i am calling intent for:

startActivityforR         


        
2条回答
  •  后悔当初
    2021-01-19 18:25

    When You start the new Activity then the current Activity gets hidden and new Activity is placed on top of the stack. Now if you press the back button on the new Activity then the first activity should come up in its current state (If it wasn't destroyed, calling finish()) where it was left i.e. if the check box was checked then it should remain checked. You don't need to save the activity state unless the orientation is changed or the activity is destroyed.

    Are you sure you are not doing any thing in the onActivityResult or onResume() method which effects the state of the check box? I would recommend to first comment out all the code in both the methods and see if your check box retains the state. Also can you also make sure that the code itself doesn't uncheck the checkbox before starting the new Activity?

提交回复
热议问题