高级任务杀手不要'正确杀死我的应用程序

时间:2013-06-17 11:55:28

标签: android task kill

我已经创建了一个Android应用程序(功能)。

我的问题是当人们使用高级任务杀手(什么是无用的)时,我的所有变量都被擦除但是应用程序不会被完全杀死,它会再次启动但是它会丢失所有数据。我希望应用程序完全杀死并重新开始。

有人有想法吗?

1 个答案:

答案 0 :(得分:2)

为什么不通过保存所有数据并在方法onSaveInstanceStateonRestoreInstanceState中恢复数据来修改处理这类情况的应用程序?

编辑:

@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");
}