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. Go back screen when back button is pressed on android does not work, app quits
Forum Updated to NodeBB v4.3 + New Features

Go back screen when back button is pressed on android does not work, app quits

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 2.2k Views 2 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.
  • R Offline
    R Offline
    RudolfVonKrugstein
    wrote on last edited by
    #1

    I am trying to implement a behavior on android when the back-button is pressed. So I do this in main.qml (in the ApplicationWindow):

     onClosing: {
            console.log("Testing")
            if (Qt.platform.os == "android") {
                console.log("Testing for andorid")
                if (stackView.depth > 1) {
                    stackView.pop();
                    console.log("Closing")
                    close.accepted = true;
                } else { Qt.quit(); }
            }
        }
    

    If I press the back button on android, this is the output:

    D/Aerger  ( 5712): qrc:/main.qml:66 (onClosing): qml: Testing
    D/Aerger  ( 5712): qrc:/main.qml:68 (onClosing): qml: Testing for andorid
    D/Aerger  ( 5712): qrc:/main.qml:71 (onClosing): qml: Closing
    I/ActivityManager(  561): Process de.goodpoint_hd.aerger (pid 5712) has died
    

    AND the application quits! From the output, I can see that "close.accepted = true" is called. Should that not prevent the event from having an effect?

    What am I doing wrong?
    Thanks!
    Nathan

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on last edited by Carmoneer
      #2

      Not sure if you resolved your issue or not, but a 'solution' was posted here

      1 Reply Last reply
      0
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by
        #3

        Hey,you can go to the previous screen using back button on your Android Phone
        by using this code.

        Keys.onReleased: {
        if (event.key === Qt.Key_Back) {
        console.log("Back button of phone pressed")
        event.accepted = true
        }
        }

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        1 Reply Last reply
        1

        • Login

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