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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:06:40+00:00 2026-06-07T12:06:40+00:00

I am learning how to set up preferences in an android application. I have

  • 0

I am learning how to set up preferences in an android application. I have a file res/xml/prefs.xml with a few different component(?) things in it. This is referenced by Prefs.java, which uses addPreferencesFromResource(R.xml.prefs); in its onCreate() method. As I understand, the prefs.xml file sets up the preferences, and the Prefs.java file accesses the prefs.xml to give it logic (that I would then program).
Then in my Manifest, I have one of the activities as

<activity
    android:name=".Prefs"
    android:label="Preferences" >
    <intent-filter>
        <action android:name="com.example.lesson1.PREFS" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

Not really sure if Manifest references Prefs.java or if it’s the other way around or what.

In addition (the most confusing right now), I have another file called Splash.java, which displays a splash screen. On the splash screen’s onCreate(), it does this:

    MediaPlayer ourSong = MediaPlayer.create(Splash.this, R.raw.splash);
    SharedPreferences getPrefs = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext()); 
    boolean music = getPrefs.getBoolean("checkbox", true);
    if (music) {
        ourSong.start();
    }

I’m not really sure how this knows where the preferences (any one of them, or whichever one it references to) are. I never told it that prefs.xml is the preferences file, or where it is. So is this a default that the preferences are in res/xml/prefs.xml and it knows that automatically?
I’m just really confused aboout the whole order of things. Which file references which? How does the manifest come into play here (it seems like it just points to the .java file to tell the android app that it’s there, but i don’t really know). And finally, is it possible to state that the preferences are in a different .java and .xml file, or do they have to be called prefs.java/.xml?

Thanks, sorry if this is confusing. I’m pretty confused myself and can’t really tell if I’m making sense completely here.

  • 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-07T12:06:42+00:00Added an answer on June 7, 2026 at 12:06 pm

    When your app is compiled, various things in the res folder are compiled in. In this case the xml folder is recognized as a raw folder and R.xml.prefs is added to the autogenerated code.

    At runtime, this is treated as a raw resource and the data is read in (it’s actually built using an inflater, similar to how the layout inflater works). You can actually see the data yourself, using…

    InputStream is = context.getResources().openRawResource(R.xml.prefs);
    

    So at runtime, addPreferencesFromResource(R.xml.prefs) is enough for the preferences to be loaded.

    As for accessing the preferences, the preferences are stored in SharedPreferences. I assume you have a preference called “checkbox”, so when you call getPrefs.getBoolean("checkbox", true) it looks for that SharedPreference value, if not found (because preferences haven’t been set yet), then it returns true (the second argument).

    This is why it’s super important for you to be consistent in your defaults. It’s actually probably worth having a class dedicated to interfacing with the preferences so that you don’t accidentally default to different values in different places.

    There is a lot of auto-generation magic in the res folder. For example, everyone uses res/values/strings.xml to store their strings, but it doesn’t actually matter what the filename is. Anything in res/values/ is read and merged, and each file can be a mixture of all sorts of data types (strings, integers, colors, etc.)

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

Sidebar

Related Questions

I'm learning C#. From what I know, you have to set things up correctly
I am currently learning regex but need this quite urgently. I have a set
I am learning WPF and have this simple question. How do I set fill
I have set about learning the gtk. And when I was browsing the reference
I have this sample string : &Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office
I'm currently learning about structs, so I have the following exercise: Set a Struct
I'm learning winforms and I have set myself a simple goal of making a
I am learning STL now. I read about set container. I have question when
I have file *.data, which include data in this order: 2.5,10,U1 3,4.5,U1 3,9,U1 3.5,5.5,U1
I am currently learning jQuery and have set up a toggleSlide effect, at the

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.