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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:50:28+00:00 2026-05-20T01:50:28+00:00

I have a class that extends PreferenceActivity and shows the preference screen of my

  • 0

I have a class that extends PreferenceActivity and shows the preference screen of my app. Is it possible to check if any changes were made to the preferences?

This helps…

http://developer.android.com/reference/android/content/SharedPreferences.OnSharedPreferenceChangeListener.html

Other related post:
SharedPreferences.onSharedPreferenceChangeListener not being called consistently


public class PreferenceClass extends PreferenceActivity {

    OnSharedPreferenceChangeListener listener;

    public void onCreate(Bundle savedInstanceState) {
        SharedPreferences prefs = this.getSharedPreferences("settings", 0);
        listener = new SharedPreferences.OnSharedPreferenceChangeListener() {

            public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
                int flag = 1;
            }
        };
        prefs.registerOnSharedPreferenceChangeListener(listener);
        super.onCreate(null);
        addPreferencesFromResource(R.xml.settings);
    }
}
  • 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-05-20T01:50:29+00:00Added an answer on May 20, 2026 at 1:50 am

    Do

    SharedPreferences.OnSharedPreferenceChangeListener spChanged = new
                               SharedPreferences.OnSharedPreferenceChangeListener() {
                @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
                String key) {
            // your stuff here
        }
    };
    

    In your PreferenceActivity, ie make it a member of your PreferenceActivity class and then do registerOnSharedPreferenceChangeListener(spChanged) in the PreferenceActivity.onCreate() method.

    That’s what I do and I never have a problem.

    Else it’s your conditional checking in the listener that is at fault. Post the code.

    EDIT:

    From the code you posted, you should make prefs a class member variable so it has a global scope.

    And do prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); instead of getSharedPreferences because you haven’t created that file.

    To create a file you need to use PreferenceManager. To get a PreferenceManager, use Activity.getPreferenceManager().

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

Sidebar

Related Questions

I have a class that extends android.app.Dialog, the layout is done in an xml
I have a custom-made view that extends the View class. I would like 2
Is it possible to have multiple classes that inherit/extends same class in Google AppEngine
I have a custom class that extends Preference that I'm using in conjunction with
I have a class extending PreferenceActivity: public class PreferenceActivity extends android.preference.PreferenceActivity { @Override protected
I have a class that extends View. I override the onDraw method and allow
i have a class that extends another. when i iterate the current object i
I have a class that extends AsyncTask. In the doInBackground() method, I connect to
I have a class that extends JPanel. On the panel I have added an
I have a MyCanvas class that extends JComponent. On this canvas I have drawn

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.