Android shared preferences not saving

前端 未结 5 502
庸人自扰
庸人自扰 2020-12-05 13:12

I\'ve created an Android live wallpaper and i\'m trying to let a user choose an image from their phone and apply it as a background image, but when I launch the activity tha

5条回答
  •  忘掉有多难
    2020-12-05 13:43

    well, based on @zrgiu post, for me only worked adding editor.clear(); before use the Editor...so the final code will be something like:

    preferences = getApplicationContext().getSharedPreferences(PREFERENCES_NAME, 0);
    SharedPreferences.Editor editor = preferences.edit();
    editor.clear();
    editor.putString(SETTINGS_BACKGROUND_IMAGE, "okok");
    editor.commit();
    

    ;)

提交回复
热议问题