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, again, see how we handle the Switch
widget 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.kt
file. So, click on the appropriate tab and we will add the code a bit at a time.
First, we want a property to represent the user's option on the settings screen – whether they want decorative dividers or not.
Add the following to SettingsActivity
:
private val showDividers: Boolean = true
Now, in onCreate
, add the highlighted code to initialize prefs
, which ...
Get Android Programming with Kotlin for Beginners 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.