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. QT5.15.2 on Android sometimes doesn't wake up

QT5.15.2 on Android sometimes doesn't wake up

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 374 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.
  • T Offline
    T Offline
    TheoSys
    wrote on last edited by
    #1

    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
             "applicationStateChanged(Qt::ApplicationSuspended)"
            signal is sent! -->
    <meta-data android:name="android.app.background_running" 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;
            break;
    
            case Qt::ApplicationInactive:
                MSG_INFO("Switched to mode INACTIVE");
                mHasFocus = false;
            break;
    
            case Qt::ApplicationHidden:
                MSG_INFO("Switched to mode HIDDEN");
                mHasFocus = false;
            break;
    
            case Qt::ApplicationActive:
                MSG_INFO("Switched to mode ACTIVE");
                mHasFocus = true;
                playShowList();
            break;
        }
    
        if (mHasFocus && pageManager)
            pageManager->initNetworkState();
        else if (pageManager)
            pageManager->stopNetworkState();
    }
    

    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.

    A.T.

    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