An example of each is shown below: // "this" refers to a Context If you need to store preferences for a specific feature in an app, it would be more appropriate to make your own preferences. The default preferences for any app can be accessed using the PreferenceManager class and should be used to store settings data that has an effect on the app as a whole. To use the shared preferences, you can either use the default preferences or create your own. The SharedPreferences class provides easy access to preference data and a secure editor for editing preferences. This file cannot be accessed directly, but is instead accessed through the SharedPreferences class. Behind the scenes Android stores this data in a hidden XML file. They're only used to store simple data points and primitive types. Preferences aren't used to store complex objects and they're also not intended to store lists of data. Shared preferences allows you to store key/value pairs which can be used to save these small bits of data used in an application. Instead of creating a new file and keeping track of the structure of that file to store these values, Android provides a key/value storage mechanism known as shared preferences. However, what if you only need to save a few simple values? When building a settings page for an app, for example, you typically need to store simple values such as a boolean to say whether a feature should be turned on or off. Saving data out to a file is a good solution for saving large amounts of, usually complex, data.
0 Comments
Leave a Reply. |