Dependency Injection Interview Questions (Android Native)
6 Dependency Injection questions from the Android Native track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
What is dependency injection and what are the main benefits of applying it in Android?
It is a design pattern that dictates passing the dependencies an object needs from outside instead of the object creating them itself inside its constructor.
Read the full explanation - Junior
What is Hilt and what advantages does it offer over the Dagger 2 library for Android apps?
Hilt is an official library built on top of Dagger to simplify its use on Android by providing predefined standard components for screen lifecycles and removing the need to write complex boilerplate code by hand.
Read the full explanation - Mid-level
What is the role of the basic annotations in Hilt: @HiltAndroidApp, @AndroidEntryPoint, and @Inject?
@HiltAndroidApp creates the root container, @AndroidEntryPoint prepares Android components for dependency injection, and @Inject requests the dependency or defines how to create it.
Read the full explanation - Mid-level
What is the difference between @Provides and @Binds inside Module classes in Hilt?
@Binds is a quick abstract function for binding an interface to its direct implementation; @Provides is a regular function used when building the object requires logic or when the object comes from an external library.
Read the full explanation - Mid-level
How does the component hierarchy and lifecycle scopes work in Hilt?
Scopes tie dependency objects to the lifecycle of specific Android components: @Singleton for the whole app, @ActivityScoped for the activity, and @ViewModelScoped for the ViewModel's lifecycle.
Read the full explanation - Senior
How do you resolve the conflict of providing two different instances of the same type using qualifiers in Hilt?
By defining custom annotations marked with @Qualifier to distinguish each instance (such as an authenticated network client and a public network client).
Read the full explanation