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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:38:23+00:00 2026-06-06T15:38:23+00:00

I am trying to get an example from the book Professional Android Programming with

  • 0

I am trying to get an example from the book Professional Android Programming with Mono for Android and .Net/C#
(pages 202 to 204) working.

To register and unregister a change listener it shows the following code sample:

using System;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Preferences;

namespace MonoForAndroidPreferences
{
    [Activity(Label = "User Preferences")]
    public class UserPreferences : PreferenceActivity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            this.AddPreferencesFromResource(Resource.Layout.userpreferences);
        }

        protected override void OnResume()
        {
            base.OnResume();

            this.GetPreferences(FileCreationMode.Private).RegisterOnSharedPreferenceChangeListener(this);
        }

        protected override void OnPause()
        {
            base.OnPause();

            this.GetPreferences(FileCreationMode.Private).UnregisterOnSharedPreferenceChangeListener(this);
        }

        public void OnSharedPreferenceChanged(ISharedPreferences prefs, string key)
        {
            // Do something with the changed value pointed to by key
        }
    }
}

Both RegisterOnSharedPreferenceChangeListener and UnregisterOnSharedPreferenceChangeListener of course cannot convert from UserPreferences to ISharedPreferencesOnSharedPreferenceChangeListener.

I’m not sure how the author meant for this to work. Any help would be greatly appreciated.

I also tried downloading the sample code from wrox.com but it did not include the listening for preferences changes in the sample code.

EDIT:

The following code compiles, but OnSharedPreferenceChanged never gets called when an update is made in the preferences.

    public class UserPreferences : PreferenceActivity, ISharedPreferencesOnSharedPreferenceChangeListener
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            this.AddPreferencesFromResource(Resource.Layout.userpreferences);
        }

        protected override void OnResume()
        {
            base.OnResume();

            this.GetPreferences(FileCreationMode.Private).RegisterOnSharedPreferenceChangeListener(this);
        }

        protected override void OnPause()
        {
            base.OnPause();

            this.GetPreferences(FileCreationMode.Private).UnregisterOnSharedPreferenceChangeListener(this);
        }

        void ISharedPreferencesOnSharedPreferenceChangeListener.OnSharedPreferenceChanged(ISharedPreferences prefs, string key)
        {
            // Do something with the changed value pointed to by key
        }
    }
  • 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-06T15:38:24+00:00Added an answer on June 6, 2026 at 3:38 pm

    You need to use

    PreferenceScreen.SharedPreferences.RegisterOnSharedPreferenceChangeListener(this);
    

    instead of

     this.GetPreferences(FileCreationMode.Private).RegisterOnSharedPreferenceChangeListener(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the FinchVideo example from the Programming Android book to work.
I am trying to get a simple example working from an assembly book I
I'm a newbie to scala. I'm trying an example from the book Programming Scala.
I'm trying to get the following simple Delegate example working. According to a book
I am trying out an example from the book Foundations of python network programming,
for example I'm trying to get the data from database like: using (ExplorerDataContext context
I'm trying to get an AJAX example working but i'm unable to get it
I am playing with the euclidian distance example from programming collective intelligence book, #
I am trying to test an example of search() from Stroustup's book. string quote(why
I am trying an example from Bjarne Stroustrup's C++ book, third edition. While implementing

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.