My guess is that you are acquiring the PARTIAL_WAKE_LOCK okay, but when the screen is turned off, your application goes into "background running" and by default, the AndroidManifest.xml generated by Qt disables background running.
Open your "AndroidManifest.xml" file and switch to the "XML Source." Scroll down and find this section:
<!-- Background running -->
<!-- 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"/>
<!-- Background running -->
By default, "android.app.background_running" is set to "false" and your application execution will be halted when the screen turns off or the user switches to different application running in the foreground. You need android.app.background_running to be set to "true" as I have in the above snippet.
When your application is running in the background, you are presumably not allowed to draw any changes to the screen or else suffer unexpected crashes. For my application, I only have one MainWindow displayed and I seem to be able to avoid the problem by implementing an applicationStateChanged() slot like this:
class MainWindow : public QMainWindow
{
(...)
public slots:
void applicationStateChanged(Qt::ApplicationState state);
}
void MainWindow::applicationStateChanged(Qt::ApplicationState state)
{
if(state != Qt::ApplicationActive)
{
// Don't update GUI if we're not the active application
ui->centralWidget->setVisible(false);
qDebug() << "Hiding GUI because not active state: " << state;
}
else
{
ui->centralWidget->setVisible(true);
qDebug() << "Showing GUI because active now.";
}
}
This function will get called automatically whenever the user turns off the screen or switches to a different foreground app.
From my experience, it is not 100% guaranteed that your application will remain running even with the above change (you just get to live a little longer). Android seems to have a mind of it's own where it will decide to sometimes kill off processes that aren't running in the foreground. Perhaps the situation will be better on higher end Android devices than what I have (every Android device I own has less than 1GB of RAM).
Do not use this for life support or other mission critical situations.
Edit from jpo38, as main window may be a QDialog
or possible be showing a QDialog
at some point, would'nt it be better to disable redrawing this was rather than hiding QMainWindow
's central widget?:
bool Application::notify(QObject * receiver, QEvent * event)
{
if ( event &&
event->type() == QEvent::Paint )
{
if ( applicationState() != Qt::ApplicationActive )
{
return false;
}
}
return QApplication::notify(receiver,event);
}