Adding a Pop up Menu for Preferences
My goal is to allow a user to modify the application using preference settings. To achieve this goal,
- application must provide the user with form fields for selecting preferences
- make it so the application updates itself, reflecting the user selected changes.
For the second point, this exercise teaches us to use SharedPreferences
api to pass user selection to the main activity so it can update the application state using the new preference settings. The SharedPreferences
api creates a file to store key->value pairs so it is available to other activities as well.
We use the PreferenceFragment
. It has defaults that work with the SharedPreferences
api such as saving and loading list.
It is good practice to use Fragments
when creating UI Panes such as user preferences. Fragments
are a sub-activity that has its own lifecycles. This is especially useful when creating a modular application since the activity has no outside dependencies to run its logic.