Making the Note to Self settings persist
We have already learned how to save data to the device's memory. As we implement saving the users' settings, we will also see again how we handle Switch
input and where exactly the code we have just seen will go to make our app work the way we want it to.
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 working SharedPreferences
and Editor
instances. We also want a member variable to represent the user's settings option: whether they want decorative dividers or not.
Add the following member variables to the SettingsActivity
class just after the class declaration:
private SharedPreferences mPrefs; private SharedPreferences.Editor mEditor; private boolean mShowDividers;
Import the SharedPreferences
class:
import android.content...