我想知道如何在bundle中保存变量,然后使用onResume()
方法返回数据。
答案 0 :(得分:0)
您需要覆盖onSaveInstanceState:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
super.onSaveInstanceState(savedInstanceState);
savedInstanceState.putString("key", "Hello World");
}
要恢复数据,请覆盖onRestoreInstanceState(您的onCreate也会收到此Bundle):
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
String myString = savedInstanceState.getString("key");
}
答案 1 :(得分:0)
查看onSaveInstanceState()和onRestoreInstanceState()的文档。这些是您的活动类的生命周期方法。