For some reason, this returns true every time for the default value. I uninstalled my app and re-installed and i do the following to initialize the values. But for some reason the boolean is set to true instead of false.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(LoadingActivity.this);
final int locationType = prefs.getInt(Constants.PREFS_LOCATION, 0);
final boolean skipWhatsNew = prefs.getBoolean(Constants.PREFS_DONT_SHOW_WHATS_NEW, false);
Log.v("loading activity : " , " " + skipWhatsNew);
I'm not really sure why its doing this since it used to just set the value to false before.
I already looked at similar questions but none of them helped, so any help would be nice, thanks.
Questions that i have looked at already,
Android - SharedPreference.getBoolean retrieving false even if i am storing true?
SharedPreferences.getBoolean returns true everytime
The above code is also the first time i access this, and from what i understand, it should set to false since it is being created for the first time. (first answer on this question mentions this, unless I'm wrong)
android default values for shared preferences
To fix, I put this in my AndroidManifest:
<application
android:allowBackup="false"
...>
See: https://developer.android.com/guide/topics/data/backup.html
I was not able to figure out why it is returning true as the default.
So the only solution i found was the change the string in the first parameter of
getBoolean(Constants.PREFS_DONT_SHOW_WHATS_NEW, false);
I pretty much changed this string by one character, ie "string" to "string_"
Now it returns the default value of false. I have then tested the preference by changing it to true in other sections of my app and then restarting the app and it is still true. I then un-install the app and it is reset back to false as its default whenever i do the above code.
Don't know why this has happened. If anyone has any idea, please let me know.
Thanks
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With