google-developer-training / android-kotlin-fundamentals-starter-apps

android-kotlin-fundamentals-starter-apps
Other
1.1k stars 3.32k forks source link

Use ViewmodelScope instead of creating coroutine scope #32

Closed android-dev-lxl closed 4 years ago

android-dev-lxl commented 4 years ago

Room library automatically moves database calls onto a background thread, so you don't explicitly need to move them to a background thread. A suspend @Dao method and a @Query method returning LiveData in Room automatically uses a background thread for database calls. You don't have to explicitly specify the Dispatcher.IO. Room does it for you in generated implementation.