App Failures by Koin: Story 3 — Issue With sharedViewModel()
This story highlights sharing data between Fragments via ViewModels, usage of sharedViewModel injection by Koin.
The Roadmap
As a true lover of Koin DI framework, in this series of stories, I’d like to share some of the true app failures my team gained when we started using Koin. (Most of them were found in production, unfortunately…)
Story 1 — Be Careful With Singletons
Story 2 — Unreliable Dynamic Loading
Story 3 — Issue With sharedViewModel() (we are here)
Story 4 — Does It Worth Sharing a ViewModel?
… to be continued…
If you’re not yet familiar with Koin, please first read Story 1 from this series. Otherwise, let’s continue and check how to share ViewModels between host Activity and Fragments, and what issue you may face if you decide to use Koin sharedViewModel(…) for that purpose.
Injecting ViewModel via Android
To begin with, if you’re not yet using ViewModels in your code, or you want to refresh your knowledge about it, please refer to the official docs. ViewModels are highly valuable when you need to organize some logic, store some data that will survive config changes, and…