问题
My Android Application has only one activity called MainActivity
. When I press the back-button
and run my application again, the previous activity will be destroyed. Now I want to know that is it possible to save the exact previous activity?
Thank you
回答1:
Pressing the back key kills your current activity. A user would not expect it to be saved as there is no way to go "Forward" .
You can save the important parts of your activity in SharedPreferences or a database when you press back and restore it to its previous state when the activity next starts which would give the impression that it was "saved"
回答2:
Activities are created in a stack, when you create A from B then B is now at the top of the stack, when you press the back button you are telling android that the top level of the stack (current activity) is no longer needed and it gets removed.
You will have to save state yourself and restore it if that's what you need to do when B is recreated.
one way you can use sharedpreferences
for saving state of TextView,EditView ...etc.and resigning again when activity recreated.
Thanks.maybe helpful :-)
来源:https://stackoverflow.com/questions/10047770/is-it-possible-to-save-previous-activity