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

Time:05-12

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?

CodePudding user response:

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.

  • Related