Home > Mobile >  Use sharedpreferences data storage
Use sharedpreferences data storage

Time:09-25

To log on to a APP, how to do it a second time or after multiple logins he won't be in login screen but also in the main interface,

CodePudding user response:

Save the login information, in the start page to judge whether there is the login information and then to bai jump

CodePudding user response:

reference 1st floor Otldan response:
save login information, in the start page to judge whether there is any login information and then to bai jump

Have a specific code? .

CodePudding user response:

Your APP has a start page? You said this logic is: first, the user when logging in for the first time, you keep the user account information to the Share; Back at the time of application for the second time start, at the start of interface is to determine the information in the account is correct, also can interact and server validation, verification is successful, just jump straight to the home page

CodePudding user response:

The
reference 3 floor Ande Wang reply:
start page of your APP? You said this logic is: first, the user when logging in for the first time, you keep the user account information to the Share; Back at the time of application for the second time start, at the start of interface is to determine the information in the account is correct, also can interact and server validation, validation is successful, just jump straight to the home page

We usually use the APP, for the first time login, a second don't have to log in directly to the main interface, mark? (bai) for example, the sharedpreferences is not very will

CodePudding user response:

 

Private String accountValue;
Private String passwordValue;
Private static String IP="10.7.70.75:8081";
//account
Private static String account;
//password
Private static String passw;
//login button
Private Button logbtn;
//withdraw from the text, the registered text, forget password text
Private TextView Exitv regtv, ForGetTv ChangeLa, jizmi, zidongde;
//display the user name and password
The EditText username and password;
//check box - remember the password, automatic login
Private CheckBox jizhupassw autolog;
//remember password sign
Private Boolean mPasswordFlag=false;
//automatic login sign
Private Boolean mAutoLoginFlag=false;
//define two constants a successful one failure
Private static final ints SUCCEED=665;
Private static final ints FALL=894;
//1 is 2 is Chinese English
Private static int CHANGESL=1;
Private Boolean qiehuan=false;
AlertDialog dialogs.
//want to apply for the permission
Private String [] permissions={. Manifest. Permission ACCESS_NETWORK_STATE, Manifest. Permission. ACCESS_WIFI_STATE
, the Manifest. Permission. INTERNET, Manifest. Permission. WRITE_EXTERNAL_STORAGE, Manifest. Permission. READ_EXTERNAL_STORAGE};

@ Override
Protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The setContentView (R.l ayout. Login);

//access controls
The username=the findViewById (R.i d.s ignup_user_Edta);
Password=the findViewById (R.i d.s ignup_pswd_Edta);
Logbtn=the findViewById (R.i d.s ignup_Btna);
Regtv=the findViewById (R.i d.g oto_reg_texta);
Jizhupassw=the findViewById (R.i, dc b_passworda);
Autolog=the findViewById (R.i, dc b_logina);
Exitv=the findViewById (R.i d.g oto_exit_texta);
Exitv. SetVisibility (the cause);
ForGetTv=the findViewById (R.i d.f ogetpsw_tv);
ForGetTv. SetVisibility (the cause);
ChangeLa=the findViewById (R.i, dc hangesLa_tv);
Surprised jizmi=the findViewById (R.i jeter izhumima);
Zidongde=the findViewById (R.i d.z idongdenglu);

//version, when the mobile phone system is more than 23, is necessary to determine whether permissions for
If (Build) VERSION) SDK_INT & gt;=Build. VERSION_CODES. M) {
Int e=ContextCompat. CheckSelfPermission (getApplicationContext (), permissions [3]).
Int f=ContextCompat. CheckSelfPermission (getApplicationContext (), permissions [4]);
//whether the authority has authorized GRANTED - authorization DINIED - refused to
If (e!=PackageManager. PERMISSION_GRANTED & amp; & F!=PackageManager. PERMISSION_GRANTED) {
//if not grant the permission, to prompt the user request
StartRequestPermission ();
}
}

SharedPreferences sp=getSharedPreferences (" LoadTypeApp ", MODE_PRIVATE);
//if not null
If (sp!=null) {
AccountValue=https://bbs.csdn.net/topics/sp.getString (" U ", "");
PasswordValue=https://bbs.csdn.net/topics/sp.getString (" P ", "");
MPasswordFlag=sp. GetBoolean (" Rem ", false);
MAutoLoginFlag=sp. GetBoolean (" Auto ", false);
The username. SetText (accountValue);
CHANGESL=sp. Get int (" change ", 1);
Qiehuan=sp. GetBoolean (" qiehuan ", false);
}

If (CHANGESL==2)
{
Password. SetHint (R.s tring. Passwords);
Jizmi. SetText (R.s tring. Repassws);
Zidongde. SetText (R.s tring. Autologins);
Logbtn. SetText (R.s tring. Logins);
Regtv. SetText (R.s tring. Regiss);
ChangeLa. SetText (R.s tring. Chinese);
LoginActivity. This. SetTitle (R.s tring. App_names);

} else if (CHANGESL==1) {

Password. SetHint (R.s tring. ");
Jizmi. SetText (R.s tring. Repassw);
Zidongde. SetText (R.s tring. Autologin);
Logbtn. SetText (R.s tring. Login);
Regtv. SetText (R.s tring. Regis);
ChangeLa. SetText (R.s tring. Enwen);
LoginActivity. This. SetTitle (R.s tring. App_name);
}


//sure to get the true remember password, check
If (mPasswordFlag) {
Jizhupassw. SetChecked (true);
Password. The setText (passwordValue);
} the else
{
Jizhupassw. SetChecked (false);
//to empty password input box
Password. The setText (" ");
}

//select the automatic login after direct login
If (mAutoLoginFlag) {
Autolog. SetChecked (true);
The HttpPost (accountValue passwordValue);
} the else
{
Autolog. SetChecked (false);
}

//set button listener
Logbtn. SetOnClickListener (this);
Regtv. SetOnClickListener (this);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related