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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:05:58+00:00 2026-06-15T14:05:58+00:00

I am using CheckBoxPreference for settings screen. The XML is: <?xml version=1.0 encoding=utf-8?> <PreferenceScreen

  • 0

I am using CheckBoxPreference for settings screen. The XML is:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen  xmlns:android="http://schemas.android.com/apk/res/android" >
    <CheckBoxPreference android:key="includeAddress"
                    android:title="Include Address" 
                    android:summary=""
                    android:defaultValue="true" />
    <CheckBoxPreference android:key="rememberName"
                    android:title="Remeber Name" 
                    android:summary=""
                    android:defaultValue="false" />
</PreferenceScreen>

I change the values while in the application. Once the user logs out, it must be set to default values as defined in the xml. But, it does not seem to work. They keep those values I chose last.

Having read Android docs, I found this:

PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.preference_settings, true);

But it hardly does the job! Tried other way round with SharedPreferences.

SharedPreferences preferences = getParent().getSharedPreferences("preference_settings", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.clear();
editor.commit();

It didn’t work either!

Am I missing something? How could I set preferences to their default values defined in the XML?

Thanks in advance!

  • 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-15T14:05:59+00:00Added an answer on June 15, 2026 at 2:05 pm

    the shared preferences should work, but you should use the default shared preferences..

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = preferences.edit();
    editor.clear();
    editor.commit();
    

    To get the shared preferences using file name, Android creates this name (possibly based on the package name of your project?). You can get it by putting the following code in a SettingsActivity onCreate, and seeing what preferencesName is.

    String preferencesName = this.getPreferenceManager().getSharedPreferencesName();
    

    The string should be something like “com.example.projectname_preferences”. Hard code that somewhere in your project, and pass it in to getSharedPreferences() and you should be good to go.

    AS:

     PreferenceManager.getDefaultSharedPreferences(this);
    

    Will provide an access to a preferences file that is global for the whole application package ; any activity can access the preferences (internaly, the xml file holding the preferences will be named your.application.package_preferences.xml).

    getParent().getSharedPreferences("preference_settings", MODE_PRIVATE);
    

    Will provide preferences only for the contextInstance class: only instances of the context’s class can access these preferences (said your package is still your.application.package and you’re in your.application.package.SecondActivity, internaly the preferences file is SecondActivity.xml).

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

Sidebar

Related Questions

I'am using several CheckBoxPreference in my android app to add a settings menu. But
I'm beginner in Java Android developing. I'm using Eclipse SDK 3.6.1 version. I have
I'm writing a preference screen in in xml for my Android application. My issue
in this tutorial : http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-building-application-preference-screens/ they talk about the preference state, and the following
Using the http://www.ifans.com/forums/showthread.php?t=132024 post from another question i am allowing the user to enter
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Android TelephonyManager an application can obtain the state of data activity over the
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using Java,I have to fetch multiple sets of values from an XML file to
Using android 2.3.3, I have a background Service which has a socket connection. There's

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.