Closed amitav13 closed 4 years ago
Hi!
Thanks for the question, I do intend to answer in depth, but this is actually being discussed in https://github.com/Zhuinden/simple-stack/issues/216
If you check the latest comment https://github.com/Zhuinden/simple-stack/issues/216#issuecomment-586393688, the intended current recommendation is to have a shared scoped (implicit or explicit (ScopeKey
or ScopeKey.Child
)) service, and you can retrieve the parent flow service at construction time of the child service using serviceBinder.lookupService()
.
If you want, you can expose an interface from the child flow's service, implement it on the parent service, and register that parent service with addAlias
by the name of that child interface.
That way the lookup
of the child would get the interface and doesn't know exact type, only parent knows that it has to be registered as the child interface as well.
See the scoping example for more information, and ask any further questions if the explanation is unclear.
If you need a much simpler variant, you can use the same hack Google is proposing, and get the saved state associated with the previous screen's key, and stuff into its Bundle. I need to do https://github.com/Zhuinden/simple-stack/issues/217 to make that sufficiently safe to use with the default view-based navigation, though.
You can check this example:
But I can update the Repo to actually show how two flows can interact via serviceBinder.lookupService
if needed.
@amitav13 have any of my propositions been helpful for your use-case so far?
I was just checking on the feasibility of my use-case before going in on this library. Good to see that there are some potential solutions for it. Thanks!
For future reference, I created a sample that shows how result passing can generally be done between screens: https://github.com/Zhuinden/simple-stack-tutorials/blob/f1ed762efe14a50dc615ebc073657056147a541c/app/src/main/java/com/zhuinden/simplestacktutorials/steps/step_8/features/form/FormViewModel.kt#L8
But the getSavedState
trick would also work reliably in 2.2.5+.
Hi, My use case is as follows:
I have a home screen (say H), some other screen(O) and a form-fill flow of 3 screens (S1, S2, S3). The form-fill flow can be started from either H or O. The end result of form-fill flow (S1 -> S2 -> S3) is a
data class
, sayFormData
. On form submission on S3, I want to pass back theFormData
generated to either H or O, whichever started the flow. I'd ideally like to also pass the data between S1, S2 and S3 (assuming it is lightweight parcelable data).Is it possible to achieve this flow using a single activity?