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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:48:52+00:00 2026-06-17T14:48:52+00:00

I have a EditText in a preference menu that allows me to edit a

  • 0

I have a EditText in a preference menu that allows me to edit a URL address. The problem is when I get the preference value in the mainActivity is not getting updated right away after I click OK in the Preference Menu. Not sure how to fix this problem. I tried a bunch of ideas and finally decided to ask.

public class PreferencesActivityTest extends PreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.radio_preferences);
        PreferenceManager.setDefaultValues(PreferencesActivityTest.this,
                R.xml.radio_preferences, false);
        EditTextPreference editPref =(EditTextPreference)findPreference("MyText");
        editPref.setOnPreferenceChangeListener(
                                    new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference,
                    Object newValue) {
                if (newValue.toString().length() > 0) {
                    return true;
                }
                // If now create a message to the user
                Toast.makeText(PreferencesActivityTest.this,
                        "Invalid Input", Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    }
}

PS: This code updates the newValue to what I enter in the EditTextPreference, doesn’t carry the new value to the MainActivity until I modify it again…

UPDATE:
In OnResume() I can see that the value is updated with the one that I modified in the PreferenceActivityTest from EditTextPreference. What I’m trying to do is to pass this newValue into the SetDataSource("").

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_radio);
    initializeMediaPlayer();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_edit:
        editURL();
        // make a Dialog or show an Activity
        return true;
    }
}

private void initializeMediaPlayer() {
    PreferenceManager.setDefaultValues(this, R.xml.radio_preferences, false);
    SharedPreferences pref =PreferenceManager.getDefaultSharedPreferences(this);
    String radioPath = pref.getString("MyText", "default value");
    // Toast.makeText(this, radioPath, Toast.LENGTH_SHORT).show();
    try {
        radioPlayer.reset();
        // radioPlayer.setDataSource("http://31.xx.xxx");
        // Toast.makeText(this, radioPath, Toast.LENGTH_SHORT).show();
        radioPlayer.setDataSource(radioPath);
    } catch {
    }
}

public void editURL() {
    stopPlaying();
    startActivity(new Intent(getBaseContext(), PreferencesActivityTest.class));
}

I am doing something fundamentally wrong but I need help. Thank you in advance !

  • 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-17T14:48:53+00:00Added an answer on June 17, 2026 at 2:48 pm

    how are you calling the preference activity? If you are calling it directly, you probably need to change the call to startActivityForResult so you refresh your data once you return from the Activity

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

Sidebar

Related Questions

So I have Preference EditText in my application and i Want to get that
I have an edittext, and a textwatcher that watches if SPACE arrived or not.
I have a simple preference (not EditText preference or ListPreference). I have a method
I want to restrict EditText to only get Text, not any number. I have
I have an EditText and I want to attach to it a KeyListener that
I have an EditText input that I would like to only allow numbers 1
How do I ensure UTF8 is used for a shared preference menu? I have
My listener is not getting called for some reason? This is what I have:
I have an EditText that the user can write in, when the app starts
I have an EditText that the user can write in, when the app starts

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.