April 2019
Beginner to intermediate
698 pages
15h 15m
English
Let's see how we can reload our data the next time the app is run. This code will reload the three values that the previous code saved. We could even declare our variables and initialize them with the stored values:
val username = prefs.getString(
"username", "new user")
val age = prefs.getInt("age", -1)
val subscribed = prefs.getBoolean(
"newsletter-subscriber", false)In the previous code, we load the data from disk using the function appropriate for the data type and the same label we used to save the data in the first place. What is less clear is the second argument to each of the function calls.
The getString, getInt, and getBoolean functions require a default value as the second argument. If there is no ...
Read now
Unlock full access