Android 9 and the back button
-
For a while now I've been using the Window's onClosing handler to handle Android's back button. I have a StackView in my app and the code looks something like this:
Window { onClosing: { if (Qt.platform.os == "android") { if (pageStack.depth() > 1) { pageStack.pop() close.accepted = false } } } }
This would pop the page stack until there is nothing left to pop, and then it'll exit the app. That's the behavior that google's own apps show too .
Now, this has been working fine until Android 9 came up with the bottom swipe feature. That is, whenever I use the bottom-swipe to switch between apps, my app gets this onClosing handler called. This can be reproduced easily with a plain empty QML app. Start it and use the bottom swipe. It will close. The issue now is that I cannot distinguish between "The back button has been pressed" and "The user switched to another app". In the former case I'd like to continue having the described behavior, but in the latter case I'd like to ignore the event completely. It feels really broken if the app closes itself in the middle of that swipe gesture. But I also cannot reject the close event unconditionally, because that would mean the back button would stop working completely if there's nothing left to pop from the stack.
Any suggestions?