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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:02:34+00:00 2026-06-09T12:02:34+00:00

I have a CheckBoxPreference in a FragmentPreference . When the user active the check

  • 0

I have a CheckBoxPreference in a FragmentPreference. When the user active the check box, I check if an application is installed and if not, I reset the preference on false and I open the Play Store to download the app.

Basically all works fine, but I have an issue to refresh the UI. Indeed, even if I set the preference on false before opened the Play Store, when the user come back, the box is checked (the fragment has just been paused and resumed so the preference value is ignored).

Is there a way to “refresh” the activity or the fragment?

  • 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-09T12:02:35+00:00Added an answer on June 9, 2026 at 12:02 pm

    Make your PreferenceFragment implement the OnSharedPreferenceChangeListener interface.

    In onCreate(), you can read the preference value and set the UI accordingly. For instance:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Load the preferences from an XML resource.
        addPreferencesFromResource(R.xml.shakesql_app_prefs);
    
        // Initialize pref summary label.
    
        // Get a reference to the application default shared preferences.
        SharedPreferences sp = getPreferenceScreen().getSharedPreferences();
    
        // Read the current preference value.
        String listVal =
                sp.getString(getString(R.string.preference_font_size_key),
                        getString(R.string.preference_font_size_default));
    
        // Look up the textual description corresponding to the
        // preference value and write it into the summary field.
        String listDesc = descriptionFromPref(
                listVal, 
                getResources().getStringArray(
                        R.array.preference_font_size_values), 
                        getResources().getStringArray(
                                R.array.preference_font_size_labels)
                        );
        if (!TextUtils.isEmpty(listDesc)) {
            ListPreference listPref =
                    (ListPreference) findPreference(getString(R.string.preference_font_size_key));
            listPref.setSummary(listDesc);
        }
    }
    

    Then, in onSharedPreferenceChanged(), update the UI.

    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
        Preference pref = findPreference(key);
        if (pref instanceof ListPreference) {
            // Update display title
            // Write the description for the newly selected preference 
            // in the summary field.
            ListPreference listPref = (ListPreference) pref;
            CharSequence listDesc = listPref.getEntry();
            if (!TextUtils.isEmpty(listDesc)) {
                pref.setSummary(listDesc);
            }
        }        
    }
    

    Here’s a code snippet from the AdvancedPreferences sample in API Demos to force the value of a checkbox preference.

    // Toggle the value of mCheckBoxPreference.
    if (mCheckBoxPreference != null) {
                mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a checkbox preference that takes the user to a
I need to control a CheckBoxPreference manually; I have to check a condition in
In my Preference activity, say I have two checkboxpreference. If I select the first
I have a application in which i have a preference acitivty which loads my
Have a painfully simple blog Post creator, and I'm trying to check if the
I made a simple extension of CheckBoxPreference so that I could have my own
I'm trying to create Preference Screen with a Checkbox control. <CheckBoxPreference android:summaryOn=@string/mySummaryOn android:summaryOff=@string/mySummaryOff android:key=myCB
I have this CheckBoxPreference in my code. I have implemented onSharedPreferenceChanged() in my code
I have a simple preference screen defined like this <PreferenceScreen xmlns:android=http://schemas.android.com/apk/res/android> <PreferenceCategory android:title=Security> <CheckBoxPreference
I have created a PreferenceScreen with a few checkboxes. One of them is: <CheckBoxPreference

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.