Is it possible to save previous activity?

此生再无相见时 提交于 2019-12-24 20:42:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!