Skip to content Skip to sidebar Skip to footer

Android - Sharedpreference.getboolean Retrieving False Even If I Am Storing True?

I am using SharedPreference to store the state of checkboxes but even i am storing true in it , its still retrieving false. Here is my code - @Override public void onPause() {

Solution 1:

You never call commit() on your editor I think :) Try this:

publicvoidsaveState()
{
    SharedPreferencessp= getPreferences(Context.MODE_PRIVATE);
    SharedPreferences.Editoreditor= sp.edit();
    for(inti=0; i < itemCheck.length; i++)
    {
        Booleanb= itemCheck[i];
        Log.e(TAG, b.toString());
        editor.putBoolean(i+"", itemCheck[i]);
    }
    editor.commit();
}

Solution 2:

use editor.commit() after editor.putBoolean(i+"", itemCheck[i]);

Post a Comment for "Android - Sharedpreference.getboolean Retrieving False Even If I Am Storing True?"