Benjamin Deroche
10/10/2023, 2:44 PMArkadii Ivanov
10/10/2023, 3:04 PMBenjamin Deroche
10/10/2023, 3:43 PMArkadii Ivanov
10/10/2023, 3:52 PMInstanceKeeper
- a replacement for ViewModelStore
. It manages implementations of InstanceKeeper.Instance
interface - a replacement for ViewModel
class. So you implement InstanceKeeper.Instance
interface, then in a component you call instanceKeeper.getOrCreate { ... }
. And you basically create your retained instance (aka ViewModel), and here you can supply all dependencies to it. Take care to not leak things from the hosting component!
Another approach is to make your components always retained. In this case your components survive configuration changes. And so you don't need InstanceKeeper
. But you won't be able to pass any dependencies that capture Context
or Activity
, etc. into your components.Benjamin Deroche
10/12/2023, 1:15 PMArkadii Ivanov
10/12/2023, 1:27 PMBenjamin Deroche
10/13/2023, 12:46 PMArkadii Ivanov
10/13/2023, 12:48 PMBenjamin Deroche
10/13/2023, 12:51 PM