Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android 9 and the back button
Qt 6.11 is out! See what's new in the release blog

Android 9 and the back button

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 617 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mzanetti-nymea
    wrote on last edited by mzanetti-nymea
    #1

    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?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved