//Get Instance ObjectSP = This. Getsharedpreferences ("UserInfo", context.mode_world_readable); REM_PW=(CheckBox) Findviewbyid (R.id.cb_mima); Auto_login=(CheckBox) Findviewbyid (R.id.cb_auto);//to remember the state of a password multi-box if(Sp.getboolean ("Ischeck",false)) { //set default is record password statusRem_pw.setchecked (true); Username.settext (Sp.getstring ("User_name", "" ")); LOG.V ("Testtest", sp.getstring ("user_name", "" ")); Password.settext (Sp.getstring ("PASSWORD", "" ")); LOG.V ("Testtest", Sp.getstring ("PASSWORD", "" ")); //determine the status of auto-login multi-marquee if(Sp.getboolean ("Auto_ischeck",false)) { //Set DEFAULT is auto sign-in statusAuto_login.setchecked (true); //Jump InterfaceIntent Intent =NewIntent (loginactivity. This, Mainactivity.class); Loginactivity. This. StartActivity (Intent); } }//Login Success And remember Password box is selected to save user information if(rem_pw.ischecked ()) {//Remember the user name, password,Editor Editor =Sp.edit (); Editor.putstring ("User_name", user); Editor.putstring ("PASSWORD", PWD); Editor.commit (); }//Monitor Remember password Multi box button eventRem_pw.setoncheckedchangelistener (NewOncheckedchangelistener () { Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { if(rem_pw.ischecked ()) {System.out.println ("Remember that the password is selected"); LOG.V ("Testtest", "Remember Password is selected"); Sp.edit (). Putboolean ("Ischeck",true). commit (); } Else{System.out.println ("Remember that the password is not selected"); LOG.V ("Testtest", "Remember that the password is not selected"); Sp.edit (). Putboolean ("Ischeck",false). commit (); } } }); //Listen for auto-logon Multi-marquee eventsAuto_login.setoncheckedchangelistener (NewOncheckedchangelistener () { Public voidOnCheckedChanged (Compoundbutton Buttonview,BooleanisChecked) { if(auto_login.ischecked ()) {System.out.println ("Automatic Logon is selected"); LOG.V ("Testtest", "Automatic Logon is selected"); Sp.edit (). Putboolean ("Auto_ischeck",true). commit (); } Else{System.out.println ("Automatic logon is not selected"); LOG.V ("Testtest", "Automatic login not selected"); Sp.edit (). Putboolean ("Auto_ischeck",false). commit (); } } }); }
Sharedpreferences
Getboolean (String key, Boolean defvalue): Get Boolean data
Parameter Description: Boolean defvalue does not set this value, there is no default return value in the configuration file
Android Auto Login with remember password