Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Android service / background thread
Holger Gerth last edited by
I'm currently working on a multi platform messenger app. In this app, the user should receive a notification if new messages were received. To achieve this task, I've tried two different solutions:
The first approach is a background thread with android.app.background_running set to true in the AndroidManifest.xml. This works unless the user turns the screen off. Then the thread stops after a few seconds and will run when the screen is turned on again. This seems to be due to the doze mode since API level 23, as far as I understand.
The second approach is using QtAndroidService and following the explanation from https://www.kdab.com/qt-android-create-android-service-using-qt/ and using BogDan Vatras example code (https://github.com/KDAB/android/tree/master/examples/service). At first, it's working fine. But some seconds after the app goes in the background or the screen is turned off, the service seems to stop working. When the app is back into running state and tries to communicate with the service, I just get an error message:
qt.remoteobjects: connectionToSource is null
Can someone please point me in the right direction how I can solve this problem? Maybe a working example? Any help is appreciated.
I'm using Qt 5.14.2 and 5.15 and tested with a Android 10 (API level 29) emulator and phone.