In navigation3, I want to show a dialog before exi...
# compose
p
In navigation3, I want to show a dialog before exiting the App but I have noticed that when backstack
size == 1
the
onback {}
lambda is not called. Is this by design or am I missing something basic in my setup?
Version 1.0.0-alpha06
Workaround it by using an OnBackInvokedCallback. If it is the expected path would be good to document it somewhere
i
This is kind of a fundamental part of Predictive Back - when the activity is being popped, that explicitly means nothing in the activity is handling back (that includes NavDisplay)
You might take a look at this explanation of how you should be setting up your own callback that will be called when the stack is of size one and you still don't want the user to exit your app (although like it is mentioned there, with Predictive Back, this kind of extra friction to exit just to avoid accidental exits may not even be a requirement on new enough versions of Android that have Predictive Back enabled): https://issuetracker.google.com/issues/435410221#comment4
p
Interesting 🤔, I haven't thought of predictive back and this scenario. This behavior is pretty common in banking Apps BTW. But right, it definitely adds friction. Thanks for the link.
a
although like it is mentioned there, with Predictive Back, this kind of extra friction to exit just to avoid accidental exits may not even be a requirement on new enough versions of Android that have Predictive Back enabled
I agree, but as far as I see there is no way for an app to tell whether Predictive Back is ON or OFF, so there's no way to tell if we should warn the user as a result some users will have a broken experience because developers can either choose to: • exit the app without a warning even when there is no predictive back • show the warning even when there is predictive back or am I missing something?