Android-Weekly
Android-Weekly copied to clipboard
Dagger and Coroutine improvements.
Dagger:
- In the
AppComponent, there isBuilderwhich can be replaced with theinterface Factory : AndroidInjector.Factory<MyApplication>asBuilderis deprecated in the latest version of Dagger. - The
fun inject(instance: MyApplication)can be removed asDaggerApplicationclass handles the field injections in theApplicationclass. - The
@BindsInstancefunction can be removed as theFactorygenerates this code for us.
Coroutines:
- We can use
withContext()function to switch threads in a coroutine instead of launching a new coroutine in separate thread each time. - Every function should handle the thread switching for proper execution of its body instead of relying on the caller of the function.
- There is no thread switching needed for the database operations if the function in Dao is marked as
suspend.Room uses a custom dispatcher optimised for the database operations.
@nikhilbansal97 Thank you, could you contribute to this?
Sure! Already working on it! 😀
@nikhilbansal97 Thank you :D
Hi @nikhilbansal97 Sorry for bothering you, but I want to ask if there is any update from your side, or should I work on it?