Working with Hilt Containers in an Android App

Learn how to use the Hilt dependency injection framework in Android.

Introduction

The Hilt library is the recommended dependency injection framework for Android applications. It extends the Dagger DI library and natively supports most of the core Android UI components. Hilt provides containers for every Android class and helps automatically manage their lifecycle.

Defining the Application class

All apps that use Hilt must contain an Application class annotated with the @HiltAndroidApp. We can define a custom class that extends Application and annotate it as follows:

Get hands-on with 1200+ tech skills courses.