Last active
September 6, 2022 04:56
-
-
Save meet30997/46e8904ae225d21d306f4ebf4be2c37d to your computer and use it in GitHub Desktop.
Synchronous DataStore
This file contains 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
// Using runBlocking | |
// It blocks the UI Thread | |
val userName = runBlocking { | |
dataStore.data.first()[DataStoreManager.userNameKey] | |
} | |
binding.userName.text = userName | |
// Using UI thread safe lifecycleScope | |
lifecycleScope.launch { | |
val userName = dataStoreManager.dataStore.data.first()[DataStoreManager.userNameKey] | |
binding.userName.text = userName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment