你需要重写的onSaveInstanceState(捆绑savedInstanceState)和写要更改的捆绑参数这样的应用程序的状态值:
@Override
public void onSaveInstanceState(Bundle 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.
super.onSaveInstanceState(savedInstanceState);
}
的包基本上是一种存储NVP(“名称 - 值对”)映射的方式,它将被传递到onCreate和onRestoreInstanceState,您可以从中提取如下值:
@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");
}
您通常会使用这种技术来存储应用程序的实例值(选择,未保存的文本等)。
取一些变量并存储它的值。 –
我在我的答案编辑示例链接.. – user370305
看看我编辑的答案,我给一段代码.. – user370305