Skip to content

Instantly share code, notes, and snippets.

@Shvet
Last active June 30, 2023 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shvet/60ee62a815df78d7f1bacf3d13daf61a to your computer and use it in GitHub Desktop.
Save Shvet/60ee62a815df78d7f1bacf3d13daf61a to your computer and use it in GitHub Desktop.
Android Datastore depedency Example
@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