Using Android Proto DataStore versus DataStore
Figure 5.2 shows the differences between PreferencesDataStore
, SharedPreferences
, and ProtoDataStore
. In this recipe, we will explore how we can use Proto DataStore. The Proto DataStore implementation uses DataStore and Protocol Buffers to persist typed objects to the disk.
Proto DataStore is similar to Preferences DataStore, but unlike Preferences DataStore, Proto does not use key-value pairs and just returns the generated object in the flow. The file types and structure of the data depend on the schema of the .
protoc
files.
Getting ready
We will use our already created project to show how you can use Proto DataStore in Android. We will also use already created classes and just give the functions different names.
How to do it…
- We will need to start by setting up the required dependencies, so let’s go ahead and add the following to our Gradle app-level file:
implementation "androidx.DataStore:DataStore...