android - Can't set SharedPreferences In AsyncTask? -


I'm trying to set the preferences shared in my asynctask but it does not seem to work Can anyone help me I tried already talking a billion

button / ASYNC code:

  button.setOnClickListener (New OnClickListener () {private ProgressDialog cancelDialog = null; int valid ; @Override see public void onClick (arg0) {new AsyncTask & LT ;, zero zero, zero & gt ;. () {@Override protected void doInBackground (zero ... parameter) {valid = api.validateLogin (username.getText () toString (), password.getText () .toString ()); return null;} @Override protected void onPreExecute () {cancelDialog = new ProgressDialog (LoginActivity.this); cancelDialog.setMessage ( "valid username & amp; Password "); cancelDialog.s How (); Super .onPreExecute ();} protected void (no results @OverridePostExecute) {cancelDialog.cancel (); if (valid == 2) {saved share options were sessions = get Krenalpakontekst (). Received references ( "Aksdiaaf" activity. MODE_PRIVATE); SavedSession.edit (). PutString ( "username", try username.getText (). ToString ()); {string passtext = MCrypt.bytesToHex (mcrypt.encrypt (password .getText). ToString ()); SavedSession.edit (). PutString ("password", "" + passtext); Committed to savedSession.edit (). } Hold (exception e) {e.printStackTrace (); // TODO:} // TODO:} else {// TODO:} super.onPostExecute (results); }}. Execute (); }});  

My access code:

  SharedPreferences savedSession = context.getSharedPreferences ( "xdaeaf", Activity.MODE_PRIVATE); String user name = saved session .getString ("user name", ""); String password = saved session .getString ("password", ""); System.out.println ("Username:" + Username + "Password:" + password);  

I have checked that I was passing from the empty variable to the putstring, but it is passing its values. It's not just saving when I run the accessing code again, it prints "username: password:" The values ​​are empty when trying to re-access it.

  savedSession.edit (). PutString ("username", username.getText () .toString ());  

Every call (to edit) gives you a new editor example. So you get an example, make a change and leave it alone then you get each other and commit that there is no change of value in the preferences, without any change.

Editor Editor = Saved Sessions. Edit (); Editor.putString ("Username", username.getText (). ToString ()); Editor.putString ("password", "" + passtext); Editor.commit ();

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -