0

Code for restore:

final SharedPreferences settings = getSharedPreferences("pref", 0);
        settings.getString("user", "");
        settings.getString("pw", "");

Code for store:

SharedPreferences.Editor editor = settings.edit();
                      editor.putString("user", etuser.getText().toString());
                      editor.putString("pw", etpw.getText().toString());
                      editor.commit();

This code don't work, and no error occur

1
  • what do you mean by doesnt' work? You can't get the data? how do you get it? How do you understand that you don't get the data? Commented Dec 27, 2010 at 12:46

2 Answers 2

2
    String s1 = settings.getString("user", "");
    String s2 = settings.getString("pw", "");

My point is - you returned the desired string, but you didn't assign its value to anything.

Sign up to request clarification or add additional context in comments.

1 Comment

@user547995 upvote the answer and mark it as a solution using a check under the score.
0
editor.putString("user", etuser.getText().toString());

editor.putString("pw", etpw.getText().toString());

Just as a side note, you don't need the toString().

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.