Easy operations on SharedPreferences
In this recipe, we will make use of the Android KTX library developed by Google, providing a set of useful extensions and utilities dedicated to Android app-development. We are going to apply extension functions that allow us to operate on the SharedPreferences
class in a clean and robust way.
Getting ready
In order to make use of the Android KTX library, we need to add it to the project dependencies. In our case, we will need it in the android-test
module. We can add it with the following declaration:
androidTestImplementation 'androidx.core:core-ktx:1.0.+'
We are going to implement the Android instrumented test case in order to verify the effects of the operations we'll perform on SharedPreferences
. You can examine the implementation and configuration of recipes related to the Android framework in the AndroidSamples project available in the GitHub repository: https://github.com/PacktPublishing/Kotlin-Standard-Library-Cookbook/. To follow Android-related...