Background application in Android
-
Here is a very good introduction to Qt Android services: https://www.kdab.com/qt-android-create-android-service-using-qt/
-
Hi
Have you created the Android Service ?
Can you test my example
I was following https://www.kdab.com/qt-android-create-android-service-using-qt/
But I have a problem, on my Android phone 4.2.2 service runs only when I have USB cable attached to the phone and if I disconnect, background process stops afer some 20 seconds.Best Regards
Marek -
I haven't tried it yet, but how do you determine that the service stops?
By the way: Even if the background service doesn't stop immediately, you can't really rely that a service, once started, is available forever. As far as I know, the Android operating system can kill a service at any time if it needs more resources. If you want to have the service only available when the application is also running you could probably (haven't tested it yet) periodically check if the service is still running and if not, start it again.
-
Hi,
I have edited my example description which is now:
Service has QTimer with 1 second interval that increments variable "counter" and sends it to the application. Second counter is QTime difference between time when "counter" was started and "now" time. If service is running in background two counters should have the same readings.
Installl the app, start it, reset counter, disconnect usb cable from the phone, lock the phone, and after some 30 seconds unlock the screen and counters will have different readings indicating that service actually stopped working after some 20 seconds, it wasn't killed, just freezed.Android services are less likely to be killed by the operating system than the application. They are designed for long term data operations and in fact if you check your Android phone I sure you will find that it has quite a few applications running in background, apps like alarm clock, push notifications and others.
In fact I have noticed that if for some reason service crashes it is automatically restarted by the operating system, so they are quite reliable.
Best Regards
Marek