Working with SharedPreferences

SharedPreferences is an interface for storing, accessing, and modifying data. The SharedPreferences APIs enable data storage in sets of key-value pairs.

We will set up a simple utility to handle our data storage needs for this app utilizing the SharedPreferences interface. Create a package in the project's source directory with the name storage (right-click the source directory and select New | Package):

Next, create a new Kotlin class named AppPreferences within the storage package. Type the following code into the class file:

package com.mydomain.tetris.storageimport android.content.Contextimport android.content.SharedPreferences ...

Get Kotlin Programming By Example 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.