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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.