gpt4 book ai didi

Java-Android SDK-savedInstanceState 和 onSaveInstanceState

转载 作者:行者123 更新时间:2023-12-01 09:44:36 24 4
gpt4 key购买 nike

我试图保存计数器的状态(mCreate、mRestart...等)并在 onCreate() 方法建立后加载它们。由于某种原因,每当调用 onCreate() 时,它总是恢复为“0”。

// Use these as keys when you're saving state between reconfigurations
private static final String RESTART_KEY = "restart";
private static final String RESUME_KEY = "resume";
private static final String START_KEY = "start";
private static final String CREATE_KEY = "create";

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Has previous state been saved?
if (savedInstanceState != null) {
this.mCreate = savedInstanceState.getInt(CREATE_KEY);
this.mRestart = savedInstanceState.getInt(RESTART_KEY);
this.mStart = savedInstanceState.getInt(START_KEY);
this.mResume = savedInstanceState.getInt(RESUME_KEY);
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.containsKey(RESTART_KEY);
savedInstanceState.containsKey(RESUME_KEY);
savedInstanceState.containsKey(START_KEY);
savedInstanceState.containsKey(CREATE_KEY);
}

最佳答案

你应该打电话

savedInstanceState.putInt(RESTART_KEY, _your_key_);

在“onSaveInstanceState”方法中

关于Java-Android SDK-savedInstanceState 和 onSaveInstanceState,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38169897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com