javascript - Remember Me button in android app -


i have created new plugin android app i've been working on. plugin requires use of remember me function cant seem working properly. within code i've designated use of shared properties @ top , string pass.

view thisscreensview = null;  string errormessage = ""; string errormessagetextcolor = ""; string errormessagetext = ""; string remembertexttext = ""; string remembertexttextcolor = ""; string vouchertextfieldplaceholder = ""; string vouchertextfieldsecuretextentry = ""; boolean vouchertextfieldsecuretextentrybool = false; string iphoneimage = ""; string ipadimage = ""; string errormessageinvalid = ""; string errormessageremember = "";  private textview errormessagetextview = null; private edittext vouchertextfieldedittext = null; private imageview imageview = null; private button submitbutton = null; private switch rememberswitch = null;  private drawable myheaderimagedrawable = null; private string alphaimage = "", pass; private static bt_item screenobjecttoload = null; sharedpreferences sharedpreferences; 

i have assigning variable pass designated text box code:

vouchertextfieldedittext.setvisibility(view.visible);      rememberswitch = (switch) thisscreensview.findviewbyid(r.id.rememberswitch);     // set switch on     rememberswitch.settext(errormessageremember);     rememberswitch.setchecked(true);     // attach listener check changes in state     rememberswitch.setoncheckedchangelistener(new oncheckedchangelistener() {          @override         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {              if (ischecked) {                 bt_debugger.showit(fragmentname + ":rememberswitch on");                 // switchstatus.settext("switch on");                  //vouchertextfieldedittext.settext(pref.getstring(pass, null));              } else {                 bt_debugger.showit(fragmentname + ":rememberswitch off");                 // switchstatus.settext("switch off");             }          }     });      // check current state before display screen     if (rememberswitch.ischecked()) {         bt_debugger.showit(fragmentname + ":rememberswitch on");         // switchstatus.settext("switch on");         //vouchertextfieldedittext.settext(pass);         if (vouchertextfieldedittext!=null) {             //vouchertextfieldedittext.settext(sharedpreferences.getstring(pass, ""));         }          if (pass != null) {              string textfield = sharedpreferences.getstring("pass", pass);             //vouchertextfieldedittext.settext(sharedpreferences.getstring("pass", pass));             vouchertextfieldedittext.settext(textfield);         }     }     else {         bt_debugger.showit(fragmentname + ":rememberswitch off");         // switchstatus.settext("switch off");     }      //     // submit click listener..      submitbutton = (button) thisscreensview.findviewbyid(r.id.submitbuttonvoucher);     submitbutton.setonclicklistener(new view.onclicklistener() {         public void onclick(view view) {             launchscreen(vouchertextfieldedittext.gettext().tostring());         }      });      // return layout file view screen..     return thisscreensview;  }// oncreateview... 

then set shared preferences string "pass" line of code:

if (loadscreennickname.length() > 1 && !loadscreennickname.equalsignorecase("none")) {                  // before launch next screen...                 if (!rememberswitch.ischecked()) {                     vouchertextfieldedittext.settext("");                 }                  if (rememberswitch.ischecked()){                     //vouchertextfieldedittext.settext("");                      //editor.putstring(pass, vouchertextfieldedittext.gettext().tostring().trim());                     //editor.apply();                      pass = vouchertextfieldedittext.gettext().tostring();                        sharedpreferences.editor editor = sharedpreferences.edit();                     editor.putstring("pass", pass);                     editor.apply();                   }                 errormessagetextview.setvisibility(view.gone);                 errormessagetextview.invalidate();                  //loadscreenobject(null, thisscreen);                 try {                     loadscreenwithnickname(loadscreennickname);                      foundit = 1;                  } catch (exception ex){                     log.e ("etutorprism error", "caught exception " + ex);                     ex.printstacktrace();                 }                 break;             }         } 

however exit , restart application, if remember me button checked, doesn't remember previous value , app ends crashing due null. else in code works except remember me. if anyones got ideas use them?

you not initializing sharedpreference. try initialize it.

 sharedpreferences sharedpreferences=getsharedpreferences("mypref",mode_private); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -