ruskaof
ruskaof

Reputation: 197

Best way to get the context of an activity in a viewmodel

I want to use this context to make a notification, but it should be called in a viewmodel that is made by hiltViewModel() function. How should I pass the context there?

Upvotes: 0

Views: 1336

Answers (1)

Richard Onslow Roper
Richard Onslow Roper

Reputation: 6835

I'd recommend creating a single method that accepts a context and displays the notification. This way you'll avoid memory leaks which can be caused if you store the activity's context instead.

Upvotes: 1

Related Questions