Hi, I'm trying to get a warning dialog to show whe...
# compose-android
a
Hi, I'm trying to get a warning dialog to show when the user navigates back via system action. is there a way to override this via compose nav, or does the containing activity/fragment need to override the behaviour (and update the state this way?) This is less on topic, but if this shouldnt be done due to ux guidelines or smth that'd be good to know also
s
BackHandler {} is your way to intercept the back button in compose. But yes, especially if you intercept it to avoid exiting the app, then that's really bad UX. If you do it so that you don't exit some important form which is already almost filled risking losing a lot of input, then I'd say it's okay.
a
that is the use case in mind :) thank you!
a
risking losing a lot of input
Even in this case, it would be better to persist whenever you can. On focus lost? Screen/step change? There are many opportunities. Sometimes it's not that the user pressed back, but maybe they switched to a different memory-heavy app, and the system killed your app? When they come back to yours they should still see their inputs "remembered".
On the assumption that user pressed back by mistake, the idea of asking for exit confirmation is still prone to fat fingering "Yes, exit" instead of "No, cancel". Doesn't solve the problem, just adds another layer to it.
s
You can properly handle process death while also not handling the “oh shit I went back by accident” issue. Usually going back clears that entry from the backstack, and the ViewModel attached to it and so on. It’s not so trivial. And storing transient input data into permanent storage is definitely an option, but not one I would jump to doing first thing. But it is definitely the only reliable solution to this. So it depends how important that form is.