我已经创建了一个 Android 应用程序(功能性)。
我的问题是当人们使用高级任务杀手(什么没用)时,我的所有变量都被擦除但应用程序并没有完全杀死,它再次启动但它错过了所有数据。我希望该应用程序完全杀死并完全重新启动。
有人有想法吗?
您为什么不通过保存所有数据并在方法onSaveInstanceState
和中恢复它来修改处理这些情况的应用程序onRestoreInstanceState
?
编辑:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("MyBoolean", true);
savedInstanceState.putDouble("myDouble", 1.9);
savedInstanceState.putInt("MyInt", 1);
savedInstanceState.putString("MyString", "Welcome back to Android");
// etc.
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
int myInt = savedInstanceState.getInt("MyInt");
String myString = savedInstanceState.getString("MyString");
}