Question
Cutting right to the chase: In Android development, is it good or bad practice to inject (ActivityScoped) LiveData instances into ViewModels using Hilt in order to observe the live data from multiple fragments?
Are there any major downsides to this approach, and is there a better way of achieving the same behavior? We could consider moving a portion or all of the code from the fragment view models to the activity view model, as the dependencies would suggest this is a better approach to begin with, but this would end up making the activity view model quite big.
Background
And some background, in case this helps to answer the question:
I have been working on an Android application in which we are using Hilt for dependency injection, Android's MVVM architecture components, and our interpretation of clean architecture which is more or less based on this article: https://www.raywenderlich.com/3595916-clean-architecture-tutorial-for-android-getting-started
Our app contains two activities and a couple of fragments, and each have been assigned their own view model. Recently as the application has grown, the code base has become a bit messy, partly due to many fragments (and their view models) depending on the same live data. The repositories and data sources injected into the view models are generally singleton, and so data sharing is not an issue.
However, what has happened is that we keep references to all view models in one activity, and many fragments are observing LiveData from each others' view models in order to update their views. This feels like a sub-optimal approach, and we are moving into refactoring season quite soon which will give us the opportunity to fix this.