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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:50:58+00:00 2026-06-16T22:50:58+00:00

I have created an onSharedPreferencesChangeListener which is working correctly. I know this because when

  • 0

I have created an onSharedPreferencesChangeListener which is working correctly. I know this because when I setup the listener I logged the listener and it is triggering on a change.

However, I was getting an error when I was trying to switch the key variable (saying that I need JRE 1.7+ in order to switch a string), so I changed it to if-elseif statements.

The if-elseif statements weren’t triggering so I changed the first two to if statements and put the elseif after that (thinking that the elseif might have been the problem). Still no triggering.

The weird thing is that when I logged the event trigger, I output ““+key+”” as the string and the key value is the exact strings that I’m testing for.

Here is my code, can someone point me in the right direction please?

    // logic for action when a shared preference is changed.
    prefs.registerOnSharedPreferenceChangeListener( new SharedPreferences.OnSharedPreferenceChangeListener() {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            String TAG = "UltimateScoreboard";

            if (key == "Main_Clock_Minutes") {
                msMainClockStart = Long.valueOf( prefs.getString( "Main_Clock_Minutes", "0" ) ) * 60000;
                Log.i( TAG, key + " changed: " + String.valueOf(msMainClockStart) );
            }

            if ( key == "Use_ShotClock" ) {
                useShotClock = prefs.getBoolean( "Use_ShotClock", false );

                if( useShotClock )
                    btnShotClock.setVisibility( View.VISIBLE );
                else
                    btnShotClock.setVisibility( View.INVISIBLE );

                Log.i( TAG, key );
            } 

            else if ( key == "Shot_Clock_Seconds" ) {
                msShotClockStart = Long.valueOf( prefs.getString( "Shot_Clock_Seconds", "0" ) ) * 1000;
                Log.i( TAG, key + " changed: " + Long.valueOf(msShotClockStart) );
            }
  • 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-16T22:51:00+00:00Added an answer on June 16, 2026 at 10:51 pm

    You must use the String.equals() function to compare strings. == with Strings only compares memory locations.

    For example: if (key.equals("Main_Clock_Minutes"))

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

Sidebar

Related Questions

I have created a windows service which is set to start automatically. This service
I have created a security.authentication.success event listener, which should send a line to the
I have created a Web Application in asp.net 2.0. which is working fine on
have created a Facebook App,As we know Facebook app have 2 URLs. Page Tab
I have created a search module which uses AJAX to display the results without
Have created a ATL COM project through which I am inserting Menu Items to
i have created synchronized arrayList like this import java.text.SimpleDateFormat; import java.util.*; class HelloThread {
I have created the following class implementing a ListSelectionListener interface. This class should listen
I have read this helpful post : SharedPreferences.onSharedPreferenceChangeListener not being called consistently However I
I have created a couple of PowerShell scripts which configure computers used in a

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.