'How to get hiltViewModel from Activity?

I am trying to get a view model in two places, one in the MainActivity using:

val viewModel:MyViewModel by viewModels()

The Other place is inside a compose function using:

val viewModel:MyViewModel = hiltViewModel()

When I debug, it seems that those are two different objects. Is there anyway where I can get the same object in two places ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source