I get inconsistent values from ViewModel when I use it in another activity. Why is that?
For example, I increment a value in ViewModel in activity 1 and I always get the value 0 in activity 2.
😶 2
b
Breaker ACT
03/13/2022, 4:02 PM
Every ViewModel should be bound with a lifeCycleOwner. Because your 2 activities has the difference lifeCycleOwner, so there are 2 diffrience ViewModels should be created
âž• 1
m
Mehdi Haghgoo
03/13/2022, 4:05 PM
Right! 🤦
s
Scott Kruse
03/13/2022, 4:27 PM
You can look into shared view model between 2 fragments to achieve something like this if you want