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 user's settings, we will also see 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 a working SharedPreferences and Editor reference. 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 SettingsActivity:

private ...

Get Android Programming for Beginners - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.