User not being saved, SharedPreferences

Posted by Lars on Stack Overflow See other posts from Stack Overflow or by Lars
Published on 2011-11-13T09:37:29Z Indexed on 2011/11/13 9:51 UTC
Read the original article Hit count: 258

Hi i have a inlogscreen (inlogdialog.xml), which includes 2 EditText (username, passwd) and i have a CheckBox (saveuser) with which the user can decide weather to save the username or not.

On the mainform (main.xml) i have a listner for these 3 values:

private class OnReadyListener implements MyCustomForm.ReadyListener {

    public void ready(String user, String pass, boolean save) {
        username = user;
        password = pass;
    }

}

Now i first want to save the username through SharedPreferences but it doesn`t get saved, can someone help me please?

If i check with system.out.println, the username is present in String username.

SharedPreferenes code in main.xml:

public static final String USERNM = ""; 
private SharedPreferences mPrefs; 
.......

@Override     
protected void onPause() {  
    Editor e = mPrefs.edit();   
    e.putString(USERNM, username); <----
    e.commit();     
    Toast.makeText(this, "Items saved.", Toast.LENGTH_SHORT).show();         
    super.onPause();    
}

© Stack Overflow or respective owner

Related posts about android

Related posts about sharedpreferences