0
0
Android Kotlinmobile~5 mins

Dependency injection with Hilt in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Dependency Injection (DI) in Android development?
Dependency Injection is a way to provide objects that a class needs (its dependencies) from outside, instead of creating them inside the class. It helps make code easier to test and maintain.
Click to reveal answer
beginner
What is Hilt in Android development?
Hilt is a library built on top of Dagger that simplifies dependency injection in Android apps. It provides standard components and annotations to reduce boilerplate code.
Click to reveal answer
beginner
What annotation do you use to tell Hilt to provide a class as a dependency?
You use the @Inject annotation on the constructor of the class you want Hilt to provide as a dependency.
Click to reveal answer
intermediate
How do you make an Android Activity ready for Hilt injection?
You add the @AndroidEntryPoint annotation to the Activity class. This tells Hilt to generate the necessary code to inject dependencies into that Activity.
Click to reveal answer
intermediate
What is a Hilt Module and why do you need it?
A Hilt Module is a class annotated with @Module and @InstallIn that tells Hilt how to provide dependencies that you cannot annotate with @Inject, like interfaces or third-party classes.
Click to reveal answer
Which annotation marks a class constructor for Hilt to provide its instances?
A@Provides
B@Module
C@Inject
D@AndroidEntryPoint
What annotation do you use on an Android Activity to enable Hilt injection?
A@AndroidEntryPoint
B@Inject
C@Module
D@Singleton
If you want to provide a third-party library instance with Hilt, what should you create?
AAn @Inject constructor in the library
BAn @AndroidEntryPoint annotation
CA @Singleton annotation on the library
DA Hilt Module with @Provides functions
What scope annotation would you use to make a dependency live as long as the application?
A@ActivityScoped
B@Singleton
C@FragmentScoped
D@Reusable
Which Hilt annotation specifies where a Module should be installed?
A@InstallIn
B@Module
C@Provides
D@EntryPoint
Explain how Hilt simplifies dependency injection in an Android app.
Think about how Hilt manages dependencies and Android classes with simple annotations.
You got /4 concepts.
    Describe the steps to inject a dependency into an Android Activity using Hilt.
    Focus on annotations and how Hilt connects dependencies to Android components.
    You got /4 concepts.