How to create an InstanceKeeper #58
Answered
by
arkivanov
manosbatsis
asked this question in
Q&A
-
In our multiplatform's Android module we create an InstanceKeeper singleton for DI (kodein) as follows: import androidx.lifecycle.ViewModelStore
import com.arkivanov.essenty.instancekeeper.InstanceKeeper
//...
bind<InstanceKeeper>() with singleton { InstanceKeeper(ViewModelStore()) } My questions are:
|
Beta Was this translation helpful? Give feedback.
Answered by
arkivanov
Jul 26, 2022
Replies: 1 comment 3 replies
-
It depends on how you use the InstanceKeeper. Typically it is used to survive configuration changes on Android, and yet use it in common code. So the answers are:
|
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
manosbatsis
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It depends on how you use the InstanceKeeper. Typically it is used to survive configuration changes on Android, and yet use it in common code. So the answers are:
InstanceKeeper
using aViewModelStore
from an Activity or a Fragment. SoInstanceKeeper
shouldn't be a singleton, it's supposed to be destroyed when the activity/fragment is finished.InstanceKeeper
should be usually scoped to a screen. You can create and passInstanceKeeperDispatcher
there.