Search code examples
androidkotlindependency-injectionkoin

How to share same instance of ViewModel between Activities using Koin DI?


I am using Koin library in Kotlin for DI

Koin providing by viewmodel() for get instance of ViewModel by sharedViewModel() to get same instance in fragments.

How can I get same instance of the ViewModel in activities ? I didn't find any way to achieve this.


Solution

  • After some research or discussion on architecture level and also report and issue github Koin,i found solution for this In this scenario,We should save that state/data into Repository which we need to share between multiple activities not in the viewModel and two or more different ViewModels can access same state/data that are saved in single instance of repository

    see here