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

  • Home
  • SEARCH
  • 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 8949555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:14:45+00:00 2026-06-15T13:14:45+00:00

Okay I started to implement this horrible code from Google’s android. The OnSharedPreferenceChangeListener is

  • 0

Okay I started to implement this horrible code from Google’s android. The OnSharedPreferenceChangeListener is not being called. This is my code, can you please advice?

Class definition:

private SharedPreferences sPrefs;
private PreferenceChangedListener prefsChangedListener;

I have a private inner class:

private class PreferenceChangedListener implements
        OnSharedPreferenceChangeListener {

    public void onSharedPreferenceChanged(
            SharedPreferences sharedPreferences, String key) {
        if (key == "highThreshold") {
            try {
                highThreshold = Float.parseFloat(sharedPreferences
                        .getString(key, "0"));
            } catch (Exception e) {
            }
        }
    }
}

Tried te following code in OnResume and to register the listener after the ‘Voorkeuren’ preferenceactivity is started. Both fail.

sPrefs = getPreferences(MODE_PRIVATE);
prefsChangedListener = new PreferenceChangedListener(); 
sPrefs.registerOnSharedPreferenceChangeListener(prefsChangedListener );

I defined a class Voorkeuren which extends PreferenceActivity

public class Voorkeuren extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_voorkeuren, menu);
        return true;
    }
}

Which I open as following:

Intent intent = new Intent(getBaseContext(),Voorkeuren.class);
startActivity(intent);

The class shows up fine, and stores the values between sessions. But my application should not be polling if settings chagned. Any ideas? I have red something about an SharedPreferences.Editor but I am not sure how it is related.

  • 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-15T13:14:46+00:00Added an answer on June 15, 2026 at 1:14 pm

    Not sure what your question is and what is desired.

    But there is one change that you need to do. Replace this in onResume

    sPrefs = getPreferences(MODE_PRIVATE);
    prefsChangedListener = new PreferenceChangedListener(); 
    sPrefs.registerOnSharedPreferenceChangeListener(prefsChangedListener );
    

    to

    sPrefs = PreferenceManager.getDefaultSharedPreferences(this);;
    prefsChangedListener = new PreferenceChangedListener(); 
    sPrefs.registerOnSharedPreferenceChangeListener(prefsChangedListener); 
    

    in onCreate()

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

Sidebar

Related Questions

Okay I just started with Django and it's totally different from PHP. I installed
Okay firstly I just started C# so I'm not exactly the most skilled programmer
Okay. I started developing an Android App for our enterprise web app. Just started
Okay. I have been trying organise this nsmutable array so my program can use
Okay so I am not sure if a lot of you have started to
Prepared Statements Okay, I've just started taking a look at MySQLi prepared statements. This
Okay, I recently started learning Java/Android so I look up a lot of tutorials
Okay so I have started a new language in class. We are learning Scheme
Okay this question is very simple: I have a facebook page, and a website.
Okay, I feel a bit foolish for having to ask this but I guess

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.