我有一个变量,我已经成功地使用 onSaveInstanceState 保存和恢复了它。
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); // the UI component values are saved here.
outState.putDouble("VALUE", liter);
Toast.makeText(this, "Activity state saved", Toast.LENGTH_LONG).show();
}
但这只对销毁活动时有效。我想通过重写onPause()方法来保存相同的变量,并在活动不再暂停时获取它,有什么想法吗?非常感谢!