Saving the state of an activity before pressing the back button

I am currently building an android app which requires saving the state of my variables and views when the back button is pressed. I know the onSaveInstanceState() would work for scenarios which involve change in orientation but how do I get it to save when I use the back button.


You may override finish() method and do saving there. This method is called when the activity is finished — that means, it's removed from activity stack. By default this happens when you press back button.


You can override,

@Override
public void onBackPressed() {
super.onBackPressed();
}

and save the state in Shared Preferences.


正如Sarge所说的,你可以重写onFinish()并将数据保存在首选项,AppDelegate等中。或者你可以保存数据并将它发送到activityResult的上一个活动,或者你可以尝试找到适当的活动标记,活动不会被杀死。

链接地址: http://www.djcxy.com/p/31904.html

上一篇: linq groupby问题

下一篇: 在按下后退按钮之前保存活动的状态