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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:09:26+00:00 2026-05-16T10:09:26+00:00

Have following setup: MainActivity class – extends activity MyLayout class – extends View Prefs

  • 0

Have following setup:

MainActivity class – extends activity

MyLayout class – extends View

Prefs class – extends PreferenceActivity and implements OnSharedPreferenceChangeListener

MainActivity creates a MyLayout class and sets it as its contentview. Once the user presses on the menu, Prefs class starts where the user can change some settings.

What I want is that, once the user changes a setting, the overloaded OnsharedPreferenceChanged method in the Prefs class will be called and from there I would like to invoke public methods on the MyLayout class that was created in the MainActivity.

How can I do this?

  • 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-16T10:09:27+00:00Added an answer on May 16, 2026 at 10:09 am

    Don’t overload onSharedPreferenceChanged method in preferenceactivity. Get an instance of the shared preference in your MainActivity, and then register an onsharedpreferencechangedlistener on that inside of your mainactivity

    
    
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    
    pref.registerOnSharedPreferenceChangeListener(prefListener);
    
    

    And then you can create a new preference listener

    
        OnSharedPreferenceChangeListener prefListener = new OnSharedPreferenceChangeListener() {
    
            @Override
            public void onSharedPreferenceChanged(
                    SharedPreferences sharedPreferences, String key) {
                // Do stuff
            }
    
        };
    
    

    You should also unregister the listener in onPause() unless you need it to persist, otherwise unregister it on onStop()

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

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I too had difficulty finding examples for Kohana3, bestattendance's example… May 16, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer Writing your own home screen application is possible. It is… May 16, 2026 at 5:33 pm
  • Editorial Team
    Editorial Team added an answer What you see is what you get - the server… May 16, 2026 at 5:33 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following setup: ASP.net 3.5 Web Site Project C# Class Library with
I have following setup: html: <div id=holder> <div> <img/> <img/> </div> </div> css #holder
I have following setup, but when I put 1024 and replace all 512 with
I have the following setup: Code on my local machine (OS X) shared as
I have the following setup: <VirtualHost *:80> ServerName svn.project1.com <Location /> DAV svn SVNPath
I have the following setup for my Blog Data Model: Blog Articles Categories -----
I have a following setup: App - Magnolia site running under Tomcat 6.0.16 ISAPI
I have the following setup, and I need to know how to persist state.
I have the following setup for my daily/main/only development environment Hardware/Tin = 4gb ram,
I have the following setup: Tasks, Accounts and Groups tables. Tasks can be assigned

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.