我正在做一个用户解锁关卡的测验,但是当他关闭应用程序时,所有进度都会丢失,并且他必须再次重做所有内容。如何解决此问题并自动保存用户的进度?或者通过点击按钮,我不知道
答案 0 :(得分:0)
您可以将其保存在 SharedPreferences 中,并在每次打开应用程序时检查它的值。
为了节省价值:
SharedPreferences sp = getSharedPreferences("YourFileName", Context.MODE_PRIVATE); //YourFileName= Any file name you give it
SharedPreferences.Editor editor = sp.edit();
editor.putString("levels", your_level_value); //levels=key at which data is stored, your_level_value=No. of levels completed
editor.apply();
要检索价值:
SharedPreferences sp = getSharedPreferences("YourFileName", Context.MODE_PRIVATE); //YourFileName= Any file name you give it
String levelCompleted = sp.getString("levels", "0"); //levels=key at which no. of levels is saved.