This question could go in <#C0B8M7BUY|android> or ...
# compose
j
This question could go in #android or here, but I’m looking for resolutions specific to a compose only app so I’ll post here. We’re seeing an issue in our app around Deeplink navigation. We’ve set up our app to be opened by links to our web app on Android. We decided we wanted the launchMode of our activity to be
singleTask
so that our app does not have multiple instances running in different tasks. When we open a task we are seeing two instances of our Activity being created which has lead to some issues. More in 🧵
The two instances of the activity are created and then one of them is destroyed about 200-500 ms later.
Not only are there two instances of the activity, but this results in two instances of our composables being executed and 2 instances of the view model for the current screen being created.
We are doing some things on init of that first VM that are problematic when done twice. To solve this we’ve added a Coordinator class which basically serves as a lock or semaphore to ensure that only one instance does the action
If we make the launchmode=standard then this does not happen, but we really feel like the singleTask experience is better for our app.
Is this behavior expected and if it is, then are there better ways to work around it/handle it?
i
singleTask is always the wrong approach, particularly with multi-window, tablets, and foldables
here's me back in 2018 suggesting that you don't use any of the launchMode flags, they are not what you want on any modern version of Android:

https://youtu.be/2k8x8V77CrU?t=1678

j
Thanks Ian for the quick response so late at night!
I’ll check that video out.