I have an application which has a Prefernces Class and I want to know how could i make so that when the application is started the settings to be applied even before entering the preferences ( settings ) class. I have a getPrefs() void method which is called when i press “Save” Button in preference activity.
So, could you help me and tell what should I do the “default” preferences to be applied when entering the application ? (I need getprefs method from another class )
I would be grate if you could give me some advices or tips.Thank you !
To get an instance of the
SharedPreferencesfrom anywhere in your application use:To set a value in the preferences, you need to call the editor for those preferences, then set the value for a key and finally commit the result. It can all be done in a single line:
This would store the string value
myValueon a key namedmyKeyand it will be accessible (after you commit) to any class if it has the application’s context when it callsgetDefaultSharedPreferences.To retrieve the stored value you specify the key and a fallback value in case there is no preference set with that key: