Last active
June 30, 2023 11:30
-
-
Save Shvet/60ee62a815df78d7f1bacf3d13daf61a to your computer and use it in GitHub Desktop.
Android Datastore depedency Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
@InstallIn(SingletonComponent::class) | |
class AppModule { | |
@Singleton | |
@Provides | |
fun provideDataStore(@ApplicationContext context: Context): DataStore<Preferences> { | |
return PreferenceDataStoreFactory.create( | |
corruptionHandler = ReplaceFileCorruptionHandler(produceNewData = { emptyPreferences() }), | |
produceFile = { context.preferencesDataStoreFile(Session.DATA) }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment