Lesson Plan: Unit - 05
Subject: P15A2AAD - Android Application Development
Topic of Study: Working with Application Preferences
Grade/Level: Master of Computer Applications
Objective: To understand the mechanism of Application Preferences
Time Allotment: 55 Minutes
- Working with Application Preferences
- Many applications need a lightweight data storage mechanism called shared preferences.
- Use: For storing application state, simple user information, configuration options...
- You cant share preferences outside of the package.
- Preferences are stored as groups of key/value pairs.
- Data types are supported as preference settings: Boolean values, Float values, Integer values, Long values, String values.
- Preference functionality can be found in the SharedPreferences interface of the android.content package.
- To add preferences support to your application, you must take the following steps:
- 1. Retrieve an instance of a SharedPreferences object.
- 2. Create a SharedPreferences.Editor to modify preference content.
- 3. Make changes to the preferences using the Editor.
- 4. Commit your changes.
- Creating Private Preferences:
- Individual activities can have their own private preferences.
- These preferences are for the specific Activity only and are not shared with other activities within the application.
- The activity gets only one group of private preferences.
- Exa.
- Creating Shared Preferences:
- Difference: We must name our preference set and use a different call to get the preference instance.
- There is no limit to the number of different shared preferences you can create.
- Exa.
- However, you want to declare your preference name as a variable so that you can reuse the name across multiple activities.
- Exa.
- Types of Mode
- Exa.
- Searching and Reading Preferences:
- Exa.
- Adding, Updating, and Deleting Preferences:
- Exa.
- Step by Step Example of Application Preferences:
- Exa.
- Finding Preferences Data on the Android File System (in DDMS)
- Exa.