Important: Please read the Qt Code of Conduct -

QT5.15.2 on Android sometimes doesn't wake up

  • Hi,

    I'm writing an application which simulates a panel for the controllers from AMX. It is running on Android (tested with a Samsung Galaxy S10 and Android 11). The application is configured to run in background also. Everything is working as expected. On the Android VM on my developer machine I can push the power button shortly and the display become black. Then in the application I get the signal Qt::ApplicationInactive and shortly after Qt::ApplicationSuspended. At the moment I push the power button again, even if it is after a hour, the display wakes up and the application receives the signal Qt::ApplicationActive. Then the application (QT) wakes up and continues to run.

    On the real phone happens basicly the same. But if I leave the phone suspended for at least 10 minutes and then wake up the phone, the application seems to be frozen. When I push the button to get to the screen where I can see all the running apps and select my application, it wakes up really and continues to run. Then it performs the action resulting from the last button I pushed when it was frozen.

    When I connect the phone to the debugger I can't reproduce this behaviour. Then it always gets the signals and wakes up as expected. Now I'm not sure whether QT receives the signal Qt::ApplicationActive or not. How can I debug this without a debugger? In case the signal arrives but is ignored by QT, can I force QT to wakeup? If so, how?

    I use QT5.15.2 to handle the graphical surface. In the AndroidManifest.xml file I set the option:

    <!-- Warning: changing this value to true may cause unexpected crashes if the
             application still try to draw after
            signal is sent! -->
    <meta-data android:name="" android:value="true"/>

    And in the code I'm catching the signal:

    connect(qApp, &QGuiApplication::applicationStateChanged, this, &MainWindow::appStateChanged);

    The method MainWindow::appStateChanged is implemented like this:

    void MainWindow::appStateChanged(Qt::ApplicationState state)
        DECL_TRACER("MainWindow::appStateChanged(Qt::ApplicationState state)");
        switch (state)
            case Qt::ApplicationSuspended:
                MSG_INFO("Switched to mode SUSPEND");
                mHasFocus = false;
            case Qt::ApplicationInactive:
                MSG_INFO("Switched to mode INACTIVE");
                mHasFocus = false;
            case Qt::ApplicationHidden:
                MSG_INFO("Switched to mode HIDDEN");
                mHasFocus = false;
            case Qt::ApplicationActive:
                MSG_INFO("Switched to mode ACTIVE");
                mHasFocus = true;
        if (mHasFocus && pageManager)
        else if (pageManager)

    The Macros DECL_TRACER() and MSG_INFO() writes out a message at least with the logging function __android_log_print(). The method playShowList() plays the content of a queue. The queue contains events happened during the application was suspended. And the methods pageManager->initNetworkState() and pageManager->stopNetworkState() stop and start a Java Active which reports the changes of the strength of the Wifi connection. This all works as long as the signals arrive as expected.


Log in to reply