Is there a “correct” way to return to where you we...
# compose
d
Is there a “correct” way to return to where you were in a compose app, after a redirect back from a Chrome Custom Tab? The full flow is: • User uses app and navigates a few screens deep (using NavHost, pure Compose app) • After clicking a button, we open a Custom Tab. • User goes through the browser journey and at the end of it a redirect is issued (currently using an “app” scheme, not https but doubt this matters) From there we’d like to just be returned to the same composable that launched the Custom Tab, ideally with access to the data in the redirect url.
Back in XML ways we used to introduce a wrapper Activity around the Custom Tab opening - simply so we can finish that activity and be back to where we were in our MainActivity, is this the way to go with Compose? Seems hacky
Some more background info Let’s say the user initiates a transaction in app by clicking a button, and suppose that this transaction is for a card payment. When clicking the button in app, we launch the Custom Chrome Tab with url of the payment provider etc. Once the user finishes the transaction in the web journey we get a redirect similar to
Copy code
<myAppScheme://test.something.co.uk/payment?id=aaaaaaaa-cccc-dddd-eeee-bbbbbbbbbbb8&status=success>
From there we have two options that we’d be happy with: • User is returned to the screen they last were in-app (before launching the custom tab) and we have access to the
id
and
status
from above so we potentially navigate away or do some validation • User is navigated to “Result” screen that naturally follows the screen that started the web journey. Similarly to above we’d need access to
id
and
status
Is my only good option to introduce that wrapper activity so my MainActivity stays intact or am I missing something here and there’s a Compose way to achieve this?
--- Note: If I specify a new Composable (2nd bullet point option above, a “Result” destination) with a
deepLink
with a matching
uriPattern
then the problem is that this starts a “fresh” activity with no backstack which is then awkward for the user.
---- If I change
android:launchMode
of my MainActivity to anything other than
standard
I lose the automatic navigation mentioned in the reply just above but at least I am back in my original activity and the original composable that launched the web journey. I assume that from here, I’d have to override
onNewIntent
in my Activity and manually extract the meaningful data. What would be the best way to bridge that manually parsed data back to my Composable screens? I could extract the data in
onNewIntent
in my Activity, pass it up to a
ActivityViewModel
which could then pass that to
DeepLinkRepository
. From there I could expose the data via a StateFlow that can then be consumed by my actual Composable via it’s own ViewModel, and trigger a navigation event forward to “Result” composable whenever that data is available/collected. Besides the fact I need to be careful with
launchMode
because of Task Hijacking I think the above approach might actually work. Wondering if anyone has already done something similar? Is there a potential issue that I’m not seeing yet and I’m just going down a rabbit hole?