Issue
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 of the user who has logged in, after closing and opening the application.
Solution
Use the following code:
// to save in SharedPreferences in Login
private static final String MY_PREFERENCES = "MyPreference";
private SharedPreferences sharedPreferences;
sharedPreferences = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE);
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE).edit();
editor.putString("username", "usernameValue");
editor.apply();
//to get data from SharedPreferences in Home Page
private static final String MY_PREFERENCES = "MyPreference";
private SharedPreferences sharedPreferences;
sharedPreferences = getSharedPreferences(MY_PREFERENCES, MODE_PRIVATE);
String username= SharedPreferences.getString("username", null);
Answered By - user311086
Answer Checked By - Marilyn (JavaFixing Volunteer)