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 7807409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:50:53+00:00 2026-06-02T02:50:53+00:00

I have a SharedPreferences that saves EditText input from one activity and displays the

  • 0

I have a SharedPreferences that saves EditText input from one activity and displays the String value in another activity.

When I enter an input into the EditText fields and press (a button I created) “Save” (which commits the EditText to editor), the file is stored successfully. However, the display activity (which displays the stored String values in SharedPreferences) doesn’t display the values. I am guessing it is because it is the onCreate, so the screen is “created” when it runs. How can I get it to update the EditText values when the user commits (presses save) immediately?

CustomStoreEditActivity – Just storing the user inputs (EditText entries):

    final Button saveButton = (Button) findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            if (saveButton.isClickable()) {
                SharedPreferences prefs = getSharedPreferences(
                        "customtime", 0);
                // prefs.registerOnSharedPreferenceChangeListener(this);
                final SharedPreferences.Editor edit = prefs.edit();
                EditText shopName = (EditText) findViewById(R.id.shopName);
                EditText open1 = (EditText) findViewById(R.id.open1);
                EditText close1 = (EditText) findViewById(R.id.close1);
                EditText open2 = (EditText) findViewById(R.id.open2);
                EditText close2 = (EditText) findViewById(R.id.close2);
                EditText open3 = (EditText) findViewById(R.id.open3);
                EditText close3 = (EditText) findViewById(R.id.close3);
                EditText open4 = (EditText) findViewById(R.id.open4);
                EditText close4 = (EditText) findViewById(R.id.close4);
                EditText open5 = (EditText) findViewById(R.id.open5);
                EditText close5 = (EditText) findViewById(R.id.close5);
                EditText open6 = (EditText) findViewById(R.id.open6);
                EditText close6 = (EditText) findViewById(R.id.close6);
                EditText open7 = (EditText) findViewById(R.id.open7);
                EditText close7 = (EditText) findViewById(R.id.close7);
                EditText comments = (EditText) findViewById(R.id.comments);
                edit.putString("shopName", shopName.getText().toString());
                edit.putString("Monday1", open1.getText().toString());
                edit.putString("Monday2", close1.getText().toString());
                edit.putString("Tuesday1", open2.getText().toString());
                edit.putString("Tuesday2", close2.getText().toString());
                edit.putString("Wednesday1", open3.getText().toString());
                edit.putString("Wednesday2", close3.getText().toString());
                edit.putString("Thursday1", open4.getText().toString());
                edit.putString("Thursday2", close4.getText().toString());
                edit.putString("Friday1", open5.getText().toString());
                edit.putString("Friday2", close5.getText().toString());
                edit.putString("Saturday1", open6.getText().toString());
                edit.putString("Saturday2", close6.getText().toString());
                edit.putString("Sunday1", open7.getText().toString());
                edit.putString("Sunday2", close7.getText().toString());
                edit.putString("comments", comments.getText().toString());
                edit.commit();
                Intent myIntent = new Intent(getBaseContext(),
                        CustomStoreActivity.class);
                myIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(myIntent);

                Toast.makeText(getBaseContext(), "Opening Hours Saved!",
                        Toast.LENGTH_SHORT).show();

            }

        }
    });

}

CustomStoreActivity – where I believe the problem lies:

    private void displayPreferences(){

    SharedPreferences prefs = getSharedPreferences("customtime", 0);
    String shopName = prefs.getString("shopName", "Empty");
    String shopTime1 = prefs.getString("Monday1", " ");
    String shopTime2 = prefs.getString("Monday2",  " ");
    String shopComments = prefs.getString("comments", "");

    TextView displayPrefs = (TextView) findViewById(R.id.displayPrefs);

    displayPrefs.setText(shopName + shopTime1 + shopTime2 + shopComments);

}

Thank you for your ample time.

  • 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-02T02:50:54+00:00Added an answer on June 2, 2026 at 2:50 am

    I think part of what you’re looking for is to put your CustomStoreActivity code in onResume instead of onCreate. Whatever code you move into onResume will occur whenever the CustomStoreActivity is brought to the front (including when it is first created).

    Another alternative, assuming that CustomStoreActivity is used to launch the Activity that contains the EditTexts, is to use startActivityForResult and pass the data back in the result Intent instead of using the SharedPreferences. Here is a simple example (though note that the setResult call in this example is passed null where you would want to pass in an Intent, as documented here in the Android docs).

    It also seems like you’re trying to use your second Activity like a dialog box with editable fields. If that’s the case, yet another alternative is to actually use a variant of the Dialog class within your CustomStoreActivity class instead of creating another Activity to act like one. See the Android doc for dialogs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble restored SharedPreferences into an activity separate from the original. I
I have a SharedPreferences that currently works in one class but doesn't work in
I am trying to save a date in one activity and then have that
I have an application that gets an api key and account name from a
I have this problem. I read with BufferedReader text from one system file, this
I have this problem. I read with BufferedReader text from one system file, this
In my app I have 5 String arrays that represent different fields of objects.
I have one question about C2DM, I registered yesterday and I got email that
I have an app that puts a marker down and saves it. I am
I have 2 processes in my application. From one process i save data in

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.