I found all the answers here and tried all the solutions, but my general privileges are not permanent.
Here is my code:
public static void setActivated(boolean activated) { SharedPreferences sp = Utils.getContext().getSharedPreferences( USER_PREFS, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putBoolean(ASD, activated); editor.commit(); } public static boolean isActivated() { SharedPreferences sp = Utils.getContext().getSharedPreferences(USER_PREFS, Context.MODE_PRIVATE); return sp.getBoolean(ASD, true); }
I also tried:
editor.clear(); editor.put .. editor.commit();
I also tried using
editor.apply();
I even tried with .apply () and .commit () and no luck.
Another idea was to try using a different mode for the files:
...getSharedPreferences(USER_PREFS, Context.MODE_MULTI_PROCESS);
The problem is that the stored values โโare not constant. If I close the application and then open it again, all values โโwill be incorrect.
Does anyone have any ideas? I would also mention that the problem is only in some devices, for example, HTC One S, Samsung Galaxy S3 (I tested another S3 and worked fine).
EDIT: I cause the button clicks to be saved on the listener, and I call isActivated when the fragment loads (after onViewCreated ()).
Thanks!
source share