Android Activity Lifecycle in Qt.
-
I asked this question before but I got no replies. I will ask again using different words. I have a test App that does some work and when I select home it goes into the background but it keeps running.
I need to shut down part of my app when it is in the background. This will help me from killing the battery. How do you get notified about this in a Qt App. I don’t see how to get to onPause() or onResume(). How do you find out when you’re going into or coming out of the background?
-
Hi,
Actually I belive Qt5.2 introduces such a feature, have a look at "QGuiApplication::applicationStateChanged":http://doc-snapshot.qt-project.org/qt5-stable/qguiapplication.html#applicationStateChanged signal.
Without this, you would have to register your C++ native state handling methods into Java environmet and then modify QtActivity.java in order to make it call these methods upon app state change, see how its done "here":http://sourceforge.net/p/erebusrpg/code/ci/master/tree/main.cpp#l72 & "here":http://sourceforge.net/p/erebusrpg/code/ci/master/tree/android/src/org/kde/necessitas/origo/QtActivity.java#l87 -
Thanks that worked for me.
-
[quote author="terenty" date="1386097969"]Hi,
Actually I belive Qt5.2 introduces such a feature, have a look at "QGuiApplication::applicationStateChanged":http://doc-snapshot.qt-project.org/qt5-stable/qguiapplication.html#applicationStateChanged signal.[/quote]I can't find the way to use it in regular QML application. Is there a doc or manual about it?
-
Well, looks like Connections to rescue here:
@
Connections {
target: Qt.application
onStateChanged: {
switch (Qt.application.state) {
case Qt.ApplicationSuspended:
case Qt.ApplicationHidden:
break
case Qt.ApplicationActive:
break
}
}
}
@ -
Well, looks like Connections to rescue here:
@
Connections {
target: Qt.application
onStateChanged: {
switch (Qt.application.state) {
case Qt.ApplicationSuspended:
case Qt.ApplicationHidden:
break
case Qt.ApplicationActive:
break
}
}
}
@