Making the Note To Self app's settings persist
We have already learned how to save data to the device's memory. As we implement saving users' settings, we will also see again how we handle the CheckBox
, RadioGroup
, and RadioButton
input.
Coding the SettingsActivity class
Most of the action will take place in the SettingsActivity.java
file. So, click on the appropriate tab and we will add the code a bit at a time.
First, we need some member variables that will give us a working SharedPreferences
and Editor
reference. We also want a member variable to represent each of the users' settings options. We need one for sound (boolean
for on or off) and int
for their preferred animation option (fast, slow, or none). Furthermore, as you will see in the next code, we have three member variables: public
, static
, and final
. These serve several purposes.
As they are final, they cannot be changed, so they are useful for remembering the three possible states the animation option can be...