java - Preferences in Android - how does it know? -
I'm learning how to set up preferences in the Android application. I have a file race / XML / prefix XML is that there are some different components (?) Things. It is referenced by Prefs.java, which is the Actually not sure whether the reference is prefs.java or if it is around or what happened. Besides (most deceptive right now), I have a splash. File, which shows a splash screen. At I'm not sure how it knows that preferences (any one of them or anyone who refers to it) I never said that prefs.xml is the preferences file, Or where it is. Is it a default that preferences are in When your app is compiled, different things are compiled inside the reserve folder. In this case the XML folder is identified as a raw folder and added in the At runtime, it is considered as a raw resource and data is read (this is actually built using the flyer, as the layout flyer works). You can actually see your data ... On the runtime, Preferences, preferences are shared. I think you have a preference for the "checkbox" name, so when you call This is the reason why it is important for you to be consistent in your default, in fact, there is a class value devoted to interfering with preferences so that you can differentiate between different values Do not miss. There are lots of auto generation magic in the resolution folder. For example, everyone uses addPreferencesFromResource (R.xml.prefs); Uses its
onCreate () method in . As I understand, prefs.xml sets the file preferences, and the prefix for this argument. The Java file reaches prefs.xml (which I will then programmatically).
Then in my manifest, I have one of the activities
& gt; Activity Android: name = ".prefs" android: label = "preferences" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "com.example.lesson1.PREFS" /> & Lt; Category android: name = "android.intent.category.DEFAULT" /> & Lt; / Intent-Filter & gt; & Lt; / Activity & gt;
onCreate () of the splash screen, it does this:
Media Player ourSong = MediaPlayer.create (Splash. This, R. strap); Shared references getPrefs = PreferenceManager .getDefaultSharedPreferences (getBaseContext ()); Boolean music = getPrefs.getBoolean ("checkbox" is true); If (music) {ourSong.start (); }
res / xml / prefs.xml and do you know it yourself?
Which file references I am just confused in the whole order of things? How does the manifest appear in the game (It seems that it tells the .java file to tell the Android app that it is there, but I do not really know). And finally, is it possible to say that preferences are in a separate .java and .xml file, or should they be called prefs.java.xml? Thank you, sorry if this is confusing. I am very confused and can not really tell whether I am completely considering it here. R.xml.prefs Autogenerated code.
InputStream = Reference. GetResources () OpenRawResource (R.xml.prefs);
addPreferencesFromResource (R.xml.prefs) is enough to load preferences.
getPrefs.getBoolean ("checkbox", true) , this seems to be the shared sharing value , If not found (because preferences are not set yet), then it returns
true (second argument).
res / values / strings.xml to store their strings. , But actually what is the name of the file does not have any effect. Anything is read and mixed in
res / values / , and each file can contain all types of data types (strings, integers, colors, etc.) < / Div>
Comments
Post a Comment