Android shared preferences retrieve username and password
14,184
Create Share Preference:
SharedPreferences sp=getSharedPreferences("Login", 0);
SharedPreferences.Editor Ed=sp.edit();
Ed.putString("Unm",Value );
Ed.putString("Psw",Value);
Ed.commit();
Get Value from Share preference:
SharedPreferences sp1=this.getSharedPreferences("Login",null);
String unm=sp1.getString("Unm", null);
String pass = sp1.getString("Psw", null);
Author by
Worker123
Updated on July 22, 2022Comments
-
Worker123 almost 2 years
Im having trouble with retrieving username and password from android's sharedpreferences. I use this code to save the username and pass
SharedPreferences prefs=getSharedPreferences("File", 0); SharedPreferences.Editor e= prefs.edit(); e.putString("Email", "[email protected]").putString("Password", "password1"); e.commit(); e.putString("Email", "[email protected]").putString("Password", "password2"); e.commit(); String s=prefs.getString("Email","not found");
But i dont know how to retrieve information for user to log in. Can anybody help me figure out
-
Worker123 about 12 yearsyes yes, i just had id figured out. Thank alot :) this is the solution i was looking for!
-
Hasmukh about 12 yearsok that Good dear, if this is useful to you then accept answer..so it will help to other also..
-
LizG about 6 yearsI have a driver app and a rider app in the same package. I am trying to get the current rider id from the driver app. I did as you did above but riderId is being returned as null? What am I doing wrong?
-
LizG about 6 yearsApp A: // .. create a shared preference - share current userid with Driver String currentRider = FirebaseAuth.getInstance().getCurrentUser().getUid(); SharedPreferences sp = getSharedPreferences("Current_User", 0); SharedPreferences.Editor ed = sp.edit(); ed.putString("rider", currentRider ); ed.commit(); App B: // .... Get Value from Share preference (RiderActivity)..... SharedPreferences sp1 = this.getSharedPreferences("Current_User", 0); riderId = sp1.getString("rider", null); Log.d("RIDERID", "RiderId = " +riderId);