I get inconsistent values from ViewModel when I us...
# android
m
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
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
Right! 🤦
s
You can look into shared view model between 2 fragments to achieve something like this if you want
âž• 1