# Using an Activity from a Hilt ViewModel

DevFeed: [Using an Activity from a Hilt ViewModel](<https://devfeed.tech/articles/using-an-activity-from-a-hilt-viewmodel-25634.md>)

Original publisher: [Read original article](<https://blog.p-y.wtf/using-an-activity-from-a-hilt-viewmodel>)

Author: Pierre-Yves Ricau

Published: 2022-09-07T21:59:49Z

Content type: tutorial

Language: en

Sources: [Py's blog](<https://devfeed.tech/sources/py-s-blog.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code](<https://devfeed.tech/tags/code.md>), [component](<https://devfeed.tech/tags/component.md>), [dagger-hilt](<https://devfeed.tech/tags/dagger-hilt.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [state](<https://devfeed.tech/tags/state.md>), [view](<https://devfeed.tech/tags/view.md>), [viewmodel](<https://devfeed.tech/tags/viewmodel.md>)

## AI overview

This tutorial presents a Hilt-based technique for accessing the current Android Activity from a Hilt ViewModel. It uses scoped activity storage, an activity-scoped entry point, and lifecycle callbacks to update the reference while accounting for configuration changes and multiple activities.

## Source excerpt

👋 Hi, this is P.Y., I work as an Android Engineer at Block. This blog shares a bit of hackery to be able to access an activity instance within a Hilt ViewModel. If you come up with other interesting