Skeptick
07/16/2020, 3:39 PMStateKeeperProvider
to keep Store
during configuration change. I do it as in the example:
stateKeeperProvider.retainStore (lifecycle) {...
But when I close the fragment and reopen it, I get the error “_The supplier is already register with this key: class com.example.MyStore_”. Shouldn’t the supplier unregister in such cases? And what should I do to avoid getting this error?Arkadii Ivanov
07/16/2020, 4:15 PMArkadii Ivanov
07/16/2020, 4:17 PMretainStore(lifecycle)
?Skeptick
07/16/2020, 4:19 PMpopBackStack
. I tried this with navigation-library as well as simple fragmentManager. retainStore
I call in controller, just like in the example.Arkadii Ivanov
07/16/2020, 4:22 PMkey
for the StateKeeperController
. In case of retainStore(lifecycle)
the key
is YourStore::class.toString()
. Please make sure the StateKeeperController
is not reused by the new instance of the fragment.Skeptick
07/16/2020, 4:27 PMStateKeeperContainer
?Arkadii Ivanov
07/16/2020, 4:29 PMStateKeeperContainer
is a new thing, it is not yet released. It will go next release.Arkadii Ivanov
07/16/2020, 4:29 PMArkadii Ivanov
07/16/2020, 4:30 PMStateKeeperContainer
Arkadii Ivanov
07/16/2020, 4:30 PMStateKeeperController
is a replacement.Arkadii Ivanov
07/16/2020, 4:31 PMSkeptick
07/16/2020, 4:33 PMStateKeeperContainer
every time I want to reopen a fragment?Arkadii Ivanov
07/16/2020, 4:35 PMSkeptick
07/16/2020, 4:36 PMSkeptick
07/16/2020, 4:36 PMArkadii Ivanov
07/16/2020, 4:37 PMArkadii Ivanov
07/16/2020, 4:55 PMStateKeeper
. I will add it.
Regarding the StateKeeperContainer
instance - I think it still should be per fragment. Because the fragments have their own onSaveInstanceState
callback and we should definitely use it, not the Activity's one.Arkadii Ivanov
07/16/2020, 4:56 PMSkeptick
07/16/2020, 5:03 PMlastCustomNonConfigurationInstance
, which we make as instance of StateKeeperContainer
, and which allows Stores
to be saved during a configuration change. I don’t understand how we can achieve the same in a fragment without involving Activity 🤔Skeptick
07/16/2020, 5:08 PMArkadii Ivanov
07/16/2020, 5:12 PMlastCustomNonConfigurationInstance
you have to use Activity, and here you will need the upcoming fix.
For state preservation over process death we should use Fragment's onSaveInstanceState()Skeptick
07/16/2020, 5:24 PMunregister
manually? As far as I know, at the lifecycle callbacks level, it is impossible to distinguish between closing a fragment and re-creating it during a configuration change.Skeptick
07/16/2020, 5:28 PMArkadii Ivanov
07/16/2020, 5:32 PMretainInstance
and so the retainStore
methods will take care of unregistering.Arkadii Ivanov
07/16/2020, 5:33 PMSkeptick
07/16/2020, 5:48 PMArkadii Ivanov
07/16/2020, 7:02 PMStateKeeperProvider
instance per fragment instance. Actually the custom ViewModel implements StateKeeperProvider
. Need to think about it.Arkadii Ivanov
07/16/2020, 11:10 PMStateKeeperController
and StateKeeperProvider
should have separate instances per Fragment instance, so there is no need to unregister. I added some extensions which make everything automatically. Could you please check and let me know your thouths? https://github.com/arkivanov/MVIKotlin/pull/114Arkadii Ivanov
07/16/2020, 11:16 PMSkeptick
07/17/2020, 5:38 AM