【发布时间】:2015-12-11 03:31:25
【问题描述】:
在活动被终止之前(当OnDestroy 被调用时),我将一些int 值保存在SharedPreferences 中。
但我注意到,保存值大约需要一秒钟,但应用程序在销毁 Activity 之前不会等待。
我可以在它被杀死之前做某种Wait 吗?
这是我的例子:
@Override
public void onDestroy(){
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("finalXPos", finalX);
editor.putInt("finalYPos", finalY);
editor.commit();
super.onDestroy();
removeView();
}
=======================>> 编辑
我犯了一个错误,说这是Activity,但事实并非如此。我正在调用Service 的onDestroy,不幸的是没有onPause 方法可以覆盖那里......
【问题讨论】:
-
使用应用代替提交。解释见这里:stackoverflow.com/questions/5960678/…
-
看看编辑,看看是否有帮助;)
标签: android android-studio android-service android-sharedpreferences android-ondestroy