Search code examples
androidpreferences

storing password using shared preference in android


I am using shared preference to store password but when ever my application starts it again ask preference value .i want once i have entered the preference password it should be fixed it should ask me again and again.


Solution

  • Where you want save your password use below code -

       Editor editor = getSharedPreferences("password", 0).edit();
       editor.putString("password", "your password");
       editor.commit();
    

    And where you like to get it back put below code there -

       SharedPreferences pref = getSharedPreferences("password", 1);
       String password = pref.getString("password", "");
    

    If still its not working, Put your code out here.