Android service not running at device boot
-
Hello,
I'm trying to create a service on android which must be automatically started at device boot.
I took a look here https://doc.qt.io/qt-5/android-services.html#service-in-separate-process and I used the servicebroadcast example (available here: https://code.qt.io/cgit/qt/qtandroidextras.git/tree/examples/androidextras/services/servicebroadcast?h=5.15) as a starting point. My problem is that I don't see
the service running.
I commented out what I tought were used to communicate with the service and
what is used to start the service on demand.
As you can see in service_main.cpp I have the service main() function which
defines and starts a QAndroidService. From what I know this should be called
by the Java class ActivityUtils once the BOOT_COMPLETED has been received
(as defined from line 17 to line 21 of the android manifest).
I commented out some code of the original example because I wanted to build
up a dummy project with an android service the starts up at device boot and
does nothing. What I'm doing wrong? Here is the project I'm using for
test purposes. https://we.tl/t-uHAqL8Nt0F
I also tried to keep the project intact and to modify only the manifest (https://we.tl/t-bpK5KTCW1O) but the service still won't start at device bootThanks
-
I don't see it running at each device boot (and so I think it hasn't started). What I want to achive is a service running at each device boot (without any "user application" opened) like system services/daemons on windows/linux.
-
@software-it said in Android service not running at device boot:
I don't see it running at each device boot (and so I think it hasn't started).
As I already said, the absence of a running service doesn't mean anything on modern Android. You should add some logging and then look at the output of adb logcat to make sure that there was an attempt to start the service at boot.
What I want to achive is a service running at each device boot (without any "user application" opened) like system services/daemons on windows/linux.
Then you should use the foreground service instead of the regular service.
-
I understand.
Do you know if there are any example of foreground services on qt available online?
I looked at https://doc.qt.io/qt-5/qtexamples.html#qt-android-extras but I didn't find any example of foreground services.Thanks
-
Here is an example of Qt app for Android with foreground service that starts on device boot:
-
Thank you! It was useful to me