Go back screen when back button is pressed on android does not work, app quits
Unsolved
Mobile and Embedded
-
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 -
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
}
}