Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9313485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:53:41+00:00 2026-06-19T01:53:41+00:00

I am not sure why my code isn’t working, following the android developer guide

  • 0

I am not sure why my code isn’t working, following the android developer guide this should work. I assume that it is because I don’t have a preferences file created, I am not sure how to go about that. Could someone take a look and see if I have written everything correctly?

public static final String PREFS_NAME = "TestPrefs";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

public void Save(View v){
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    final EditText s = (EditText) findViewById(R.id.editText1);
    settings.edit().putString("TBox1", s.getText().toString());
    settings.edit().commit();
}

public void Open(View v){
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
    final EditText s = (EditText) findViewById(R.id.editText1);
    String newS = settings.getString("TBox1", "");
    s.setText(newS);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T01:53:43+00:00Added an answer on June 19, 2026 at 1:53 am

    You have to commit() on the same Editor. Commiting on another object as you have done means that the previous putString() gets lost. This means change

    settings.edit().putString("TBox1", s.getText().toString());
    settings.edit().commit();
    

    to

    settings.edit().putString("TBox1", s.getText().toString()).commit();
    

    Of course, if you have more than one thing to edit, you can keep a reference to your editor:

    Eg:

    SharedPreferences.Editor editor = settings.edit();
    editor.putString("key1", "value1");
    editor.putString("key2", "value2");
    editor.commit();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure why this code isn't working. . . I can't find the
I'm not sure why this code isn't working. Any ideas? iBooks opens, but nothing
I'm not sure why this code isn't working, so any help would be appreciated.
I'm not sure why this code isn't working. Its not going to the copy
Not sure why this isn't working. When people click the 'edit' button of my
Not sure why this isn't working. I have a timer defined, which runs a
I'm not sure why this code isn't simply drawing a triangle to screen (orthographically).
Not sure why the code below isn't working... I've tried a number of variations:
First, I'm sad to say I'm not sure whether this code should be in
This should be a really simple question but Google + my code isn't working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.