0

我想知道如何将变量保存在包中,然后使用该onResume()方法取回数据。

4

2 回答 2

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");
}
于 2012-07-21T17:40:24.033 回答
0

查看onSaveInstanceState()onRestoreInstanceState()的文档。这些是您的活动类的生命周期方法。

于 2012-07-21T17:42:23.973 回答