Qt World Summit: Register Today!

Android app based on QMainWindow fails to restart

  • I have an application which is a simple form based on a qMainWindow. The application is creating a Bluetooth Smart link, when it opens, and displays some values from the remote sensor, I have a close button (qPushButton) that disconnects the link and then call mainwindow.close() This all works OK and I go back to my android home screen, but the next time I click on the application icon in the launcher, the app doesn't start up properly, it appears to load the java splash screen and nothing else happens, if I kill this with a task manager my app will load correctly the next time around.

    I've scattered log messages throughout the C++ code (I'm actually using PyQt and pyqtdeploy) and Java code. The C++ main.cpp of pyqtdeploy is exiting normally when I call mainwindow.close(), but the Java wrapper code doesn't close, it just gets suspended to the background the last thing to be called appears to be onPanelClosed() . I get no logging at all when I try to restart the application, it just looks like it hangs on activity.xml (the splash screen). I did try adding android.os.Process.killProcess(android.os.Process.myPid()); into onPanelClosed(), this does let me close and open the application again, but onPanelClosed() is also called when I use a menu so its not a good solution. Does anyone have any pointers?

    I should add this all works just fine on Linux. I believe the issue is in the java application lifecycle in android, but I know next to nothing about Android.

    EDIT - I forgot to mention I also tried to overloading changeEvent() and seeing if I could use that to just disconnect my bluetooh and hide, but on android this event doesn't appear to work, but it does on Linux.

  • More info -

    It appears that this is unique to pyqtdeploy code and not a generic QT issue. If I try and of the example applications they stop and start OK. If I try anything with python it does not.

    I can see that the jave code QtNative.finish() is called from the native code after the native code has returned with exit code 0. After this The activity calls finish. At some point later QtApplication.invokeDelegateMethod() makes a call to the QtActivityDelegate.OnPause handler, which calls QtNative.updateApplicationState(2); which never returns......Is this because the native thread is no more?

    As a workaround I've overloaded finish within QtActivity.java

    public void finish() {
    /* force kill the app */

    Any suggestions on a real fix would be welcome.

Log in to reply