I saw some tutorials for auto login for exemple this one link, but when i use the app for the first time, how do i check if the login and password have already been inserted in Preferences Activity ? What condition should i put ?
Asked
Active
Viewed 1,299 times
1 Answers
7
SharedPreferences sp=PreferenceManager.
getDefaultSharedPreferences(context);
if(sp.contains("Username")){
//login exists assuming you are saving the username to a preference with the name "Username"
}
jkhouw1
- 7,320
- 3
- 32
- 24
-
btw to be clear: "Username" here is the key name not the value – jkhouw1 Jun 07 '11 at 19:42
-
1ok thank you for that because i didn't get it the first time, and for example in the link i put, that would be : "name" from android:key="name" , and "password" from android:key="password", if i'm right ? – Tsunaze Jun 07 '11 at 19:44
-
I suggest you don't save the password in SharedPreference, that would make it really insecure. – ferostar Jun 07 '11 at 19:49
-
but how can i do it then ? (I'm all about security too) – Tsunaze Jun 07 '11 at 19:55
-
there are some suggestions here: http://stackoverflow.com/questions/785973/what-is-the-most-appropriate-way-to-store-user-settings-in-android-application – jkhouw1 Jun 07 '11 at 19:58
-
here is my json format {"login":[{"status":"error"}]} can anyone help me with login page? – Oct 29 '14 at 06:05