Pass viewmodel instance to another class and call viewmodel.update(), viewmodel.insert() and other functions from that class


I create a ViewModel in my

AnchorViewModel anchorViewModel = new ViewModelProvider(this).get(AnchorViewModel.class);
                .observe(this, updateArObjectsOnChangeInSceneHelper::updateAnchorsInArScene);

Then, I pass the anchorViewModel to another class. Now I want to call anchorViewModel.insert() and anchorViewModel.update() from that class instead of I try that but it doesn’t trigger the updateAnchorsInArScene function. In fact, I can only trigger it when I call the anchorViewModel methods from the Am I not allowed to call ViewModel methods from a class different than the one where it was created (even if I just pass it as a reference to that other class)?

Source: Android Questions

Categorized as android, android-mvvm, android-viewmodel, java


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us