Saving a user session after logging in with SQL Server

前端 未结 1 1697
故里飘歌
故里飘歌 2021-01-29 08:11

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 openin

1条回答
  •  伪装坚强ぢ
    2021-01-29 08:49

    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);
    

    0 讨论(0)
提交回复
热议问题