I have a login form with a checkbox to let the app remember the email in `LoginActivity`. If I press the Log in button the email should be stored in `SharedPreferences` using the class `AppPreferences`.

The app remembers the email if I return to home screen by pressing home button and by pressing back.

But if I force close the app shows the default value as defined in the `Preferencemanager.getString("value", "default_value");` method. 

I have tried a lot of things people suggested on SO, but unfortunately none of the solutions worked. I even tried to solve it by putting all the `SharedPreferences` code in a separate class (see [this question](https://stackoverflow.com/questions/15251942/sharedpreferences-makes-app-force-close)).

Below I put as much code relevant to the question. So both the classes `LoginActivity` and `AppPreferences`. There is no error message given by LogCat. 

At both the Samsung devices I9100 and P3110 with Android 4.2.2 Cyanogenmod 10.1 and several different emulators this problem occurs. (I read some Samsung S devices with HoneyComb could't save SharedPreferences properly?)

---

**EDIT:**
As I forgot to mention, the project is targeted to API 17 and the minSdkVersion = 11. I only save credentials on click of Log in button.  

**EDIT 2:** This problem also occurs if phone reboots

---

the `LoginActivity` class:

```
public class LoginActivity extends Activity
{
    private static final String PREF_REMEMBER_EMAIL = "LoginCredentialsRememberEmail";
    private static final String PREF_EMAIL = "LoginCredentialsEmail";

    private String mEmail;

    private EditText mEmailView;
    private CheckBox cbRememberEmail;   

    private AppPreferences appPreferences;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        appPreferences = new AppPreferences(LoginActivity.this);

        loadUserCredentials();
    }
    @Override
  protected void onResume() {       
        super.onResume();
        loadUserCredentials();
    }

    @Override
    protected void onStart() {
        super.onStart();
        loadUserCredentials();
    }

    private void loadUserCredentials() {
        String rememberEmail = appPreferences.getPreferenceString(PREF_REMEMBER_EMAIL);
        String email = appPreferences.getPreferenceString(PREF_EMAIL);
        mEmailView = (EditText) findViewById(R.id.email);
        mEmailView.setText((rememberEmail == "1") ? email : "");
        cbRememberEmail = (CheckBox) findViewById(R.id.cbRememberEmail);
        cbRememberEmail.setChecked(rememberEmail == "1" ? true : false);
        mEmail = mPassword = "";
    }
    private void saveUserCredentials() {        
        try {
        String rememberemail = (((CheckBox) findViewById(R.id.cbRememberEmail)).isChecked()) ? "1" : "0";
        appPreferences.setPreferenceString(PREF_REMEMBER_EMAIL, rememberemail);
        String email = (rememberemail == "1") ? mEmail : "";
        appPreferences.setPreferenceString(PREF_EMAIL, email);
    }

    public void cbRememberEmailClick(View view) {
        boolean checked = ((CheckBox) findViewById(R.id.cbRememberEmail)).isChecked();
        if (checked) {
            new AlertDialog.Builder(this).setTitle(R.string.remember_email_notification_title).setMessage(R.string.remember_email_notification_message).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    ((CheckBox) findViewById(R.id.cbRememberEmail)).setChecked(true);
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    ((CheckBox) findViewById(R.id.cbRememberEmail)).setChecked(false);
                }
            }).show();
        }
    }
// ...
}

```

The `AppPreferences` class:

```
public class AppPreferences {
    Context context;

    private SharedPreferences settings = null;

    private static String LOGIN_CREDENTIALS = "com.example.login.credentials";
    private static String DEFAULT_STRING = "";

    public AppPreferences(Context context) {
        this.context = context;
        settings = PreferenceManager.getDefaultSharedPreferences(context);
    }

    private String getKey(String key) {
        return LOGIN_CREDENTIALS + "." + key;
    }

    public String getPreferenceString(String key) {
        return settings.getString(getKey(key), DEFAULT_STRING);
    }
    public void setPreferenceString(String key, String value) throws Exception {
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(getKey(key), (String) value);
        editor.commit();
    }
// ...
}

```

Any help is really appreciated, I'm stuck at this for days and it's really frustrating now. 

Thanks in advance.

Dediqated