Reputation: 526
I need to implement session for my android application after a user has successfully logs into application. But i want this by using application not webView. And this login credentials is sent to server for authentication. Can it we possible without using webView.
Upvotes: 0
Views: 217
Reputation: 3937
For this u can use preference.if The login is sucessful u can set the username and password in prefernce.if user loged out preference sets back to the defult guest account.
refer this..http://developer.android.com/reference/android/preference/Preference.html
if the login is suceesful set preference like this
String user_name_key = "Username";
String pass_word_key = "Password";
String Shared_preference_key = "Shared Preference";
private SharedPreferences USERNAME_and_PASSWORD;
public boolean setUserName(String userName) {
editor = USERNAME_and_PASSWORD.edit();
editor.putString(user_name_key, userName);
editor.commit();
return true;
}
public boolean setPassword(String password) {
editor = USERNAME_and_PASSWORD.edit();
editor.putString(pass_word_key, password);
editor.commit();
return true;
}
Upvotes: 1
Reputation: 740
You can use the SharedPreferences for this to storing the info of the logged in user .
// Access the default SharedPreferences
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
// Edit the saved preferences
editor.putString("UserName", "JaneDoe");
editor.putInt("password", "******");
editor.commit();
and these value can be retrieve in this way .
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String UserName= prefs.getString("UserName", null);
So that this info can be used in application everywhere .
Upvotes: 1