Skip to content Skip to sidebar Skip to footer

Saving A User Session After Logging In With Sql Server

I am trying to make my application with SQL Server, but I do not know how to identify the user that has logged in, after closing and opening the application. Also identify the ID o

Solution 1:

Use the following code:

// to save  in SharedPreferences in Login
private static final String MyPREFERENCES = "MyPreference";
private SharedPreferences sharedPreferences;
sharedPreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE);
SharedPreferences.Editor editor = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE).edit();
editor.putString("username", "usernameValue");
editor.apply();

//to get data from SharedPreferences in Home Page
private static final String MyPREFERENCES = "MyPreference";
private SharedPreferences sharedPreferences;
sharedPreferences = getSharedPreferences(MyPREFERENCES, MODE_PRIVATE); 
String username= SharedPreferences.getString("username", null);

Post a Comment for "Saving A User Session After Logging In With Sql Server"