我正在尝试自学一些 android 编程,但我无法让我的应用程序保存和加载用户进度。
目前我在我的活动中初始化我的变量级别和分数。然后从我的 onCreate 方法调用它:
if (savedInstanceState != null) {
// Restore value of members from saved state
playersScore = savedInstanceState.getInt(STATE_SCORE);
level = savedInstanceState.getInt(STATE_LEVEL);
} else {
playersScore = 0;
level = 0;
}
最后我有一个保存包的方法:
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putInt(STATE_SCORE, playersScore);
savedInstanceState.putInt(STATE_LEVEL, level);
super.onSaveInstanceState(savedInstanceState);
}
出于某种原因,我的捆绑包无法保存,关于我缺少什么的任何想法?