Android Question Service With B4A 8+ - how to make them work

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hi everyone
unfortunately, I still have problems to make services work. Maybe I do not understand all the tutorials and threads I've read!

I discovered that if I turn on the device, the service starts BUT DOES NOT DO ANYTHING. If the devide is on and I install the application the service works regularly.

Furthermore, the following message always appears: "The Starter service should never be started from a receiver."

I attach a simple example that should start the service automatically (every 1 minute) and that should launch a simple function.

Can anyone help me please.

I repeat that the service can not do its job only if I turn off and on again the device.

Many thanks in advance

regards
roberto
 

Attachments

  • testservice.zip
    8.8 KB · Views: 195

DonManfred

Expert
Licensed User
Longtime User
every 1 minute
There is no such thing in Android. You are not allowed to start a service in this Interval.

Do NOT use startatboot in the starterservice!
https://www.b4x.com/android/forum/threads/starter-service-consistent-single-entry-point.57599/

Notes

  • The Starter service is identified by its name. You can add a new service named Starter to an existing project and it will be the program entry point.
  • This is an optional feature. You can remove the Starter service.
  • You can call StopService(Me) in Service_Start if you don't want the service to keep on running. However this means that the service will not be able to handle events (for example you will not be able to use the asynchronous SQL methods).
  • The starter service should be excluded from compiled libraries. Its #ExcludeFromLibrary attribute is set to True by default.
  • The starter service should never be explicitly started. This means that if you want to start a service at boot then add a different service.


Android 8+ considerations
  • Starting from Android 8, the OS kills services while the app is in the foreground.
  • If you are using B4A v8.30+ then the starter service will not be killed until the whole process is killed.
  • You will see a message such as this one, 60 seconds after the app has moved to the background:
    ** Service (starter) Destroy (ignored)**
  • The above message means that the actual service is destroyed but the starter service is still available.
  • Don't make the starter service a foreground service. It will not work once the backed service is destroyed.
  • If you want to do a background task then you should add another service.
  • Related tutorial: Automatic Foreground Mode

Create another service and set its attribute to startatboot.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
thanks Manfred,

you are the best!

I disabled all functions into starter service and set-up it's the TestService with #StartAtBoot service: true.

Now works after device start-up.

but I see that there continues to be the warning message: The Starter service should never be started from a receiver.

It's correct?

thank you
 

Attachments

  • Immagine.png
    Immagine.png
    181.6 KB · Views: 217
  • testservices.zip
    8.8 KB · Views: 176
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The Starter service should never be started from a receiver.
1. You should always start a new thread for a new question.
2. You should post errors as TEXT instead of an images which nobody can read (at least not my eyes).
3. Are you sure the log is from the app you just uploaded? i fear it is a log from the last version. I don´t see any reason for the starter to start from a receiver in your uploaded project...
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This app is doing its job since yesterday....

======================================
21.02.2019 20:59:08: Counter=1
21.02.2019 20:59:08: Time=20:59:07
======================================
======================================
21.02.2019 21:14:09: Counter=2
21.02.2019 21:14:09: Time=21:14:08
======================================
======================================
21.02.2019 21:29:08: Counter=3
21.02.2019 21:29:08: Time=21:29:07
======================================
======================================
21.02.2019 21:44:09: Counter=4
21.02.2019 21:44:09: Time=21:44:08
======================================
======================================
21.02.2019 21:59:09: Counter=5
21.02.2019 21:59:09: Time=21:59:08
======================================
======================================
21.02.2019 22:14:08: Counter=6
21.02.2019 22:14:08: Time=22:14:08
======================================
======================================
21.02.2019 22:29:09: Counter=7
21.02.2019 22:29:09: Time=22:29:08
======================================
======================================
21.02.2019 22:44:08: Counter=8
21.02.2019 22:44:08: Time=22:44:07
======================================
======================================
21.02.2019 22:59:08: Counter=9
21.02.2019 22:59:08: Time=22:59:08
======================================
======================================
21.02.2019 23:14:08: Counter=10
21.02.2019 23:14:08: Time=23:14:07
======================================
======================================
21.02.2019 23:29:08: Counter=1
21.02.2019 23:29:08: Time=23:29:07
======================================
======================================
21.02.2019 23:44:09: Counter=1
21.02.2019 23:44:09: Time=23:44:07
======================================
======================================
21.02.2019 23:59:08: Counter=2
21.02.2019 23:59:08: Time=23:59:07
======================================
======================================
22.02.2019 00:14:08: Counter=3
22.02.2019 00:14:08: Time=00:14:07
======================================
======================================
22.02.2019 00:29:08: Counter=4
22.02.2019 00:29:08: Time=00:29:07
======================================
======================================
22.02.2019 00:44:09: Counter=5
22.02.2019 00:44:09: Time=00:44:07
======================================
======================================
22.02.2019 00:59:08: Counter=6
22.02.2019 00:59:08: Time=00:59:07
======================================
======================================
22.02.2019 01:14:08: Counter=7
22.02.2019 01:14:08: Time=01:14:07
======================================
======================================
22.02.2019 01:29:09: Counter=8
22.02.2019 01:29:09: Time=01:29:07
======================================
======================================
22.02.2019 01:44:08: Counter=9
22.02.2019 01:44:08: Time=01:44:07
======================================
======================================
22.02.2019 01:59:08: Counter=10
22.02.2019 01:59:08: Time=01:59:07
======================================
======================================
22.02.2019 02:14:08: Counter=11
22.02.2019 02:14:08: Time=02:14:07
======================================
======================================
22.02.2019 02:29:08: Counter=12
22.02.2019 02:29:08: Time=02:29:07
======================================
======================================
22.02.2019 02:44:08: Counter=13
22.02.2019 02:44:08: Time=02:44:07
======================================
======================================
22.02.2019 02:59:08: Counter=14
22.02.2019 02:59:08: Time=02:59:07
======================================
======================================
22.02.2019 03:14:08: Counter=15
22.02.2019 03:14:08: Time=03:14:07
======================================
======================================
22.02.2019 03:29:08: Counter=16
22.02.2019 03:29:08: Time=03:29:07
======================================
======================================
22.02.2019 03:44:07: Counter=17
22.02.2019 03:44:07: Time=03:44:07
======================================
======================================
22.02.2019 03:59:08: Counter=18
22.02.2019 03:59:08: Time=03:59:07
======================================
======================================
22.02.2019 04:14:07: Counter=19
22.02.2019 04:14:07: Time=04:14:07
======================================
======================================
22.02.2019 04:29:09: Counter=20
22.02.2019 04:29:09: Time=04:29:07
======================================
======================================
22.02.2019 04:44:08: Counter=21
22.02.2019 04:44:08: Time=04:44:07
======================================
======================================
22.02.2019 04:59:08: Counter=22
22.02.2019 04:59:08: Time=04:59:07
======================================
======================================
22.02.2019 05:14:08: Counter=23
22.02.2019 05:14:08: Time=05:14:07
======================================
======================================
22.02.2019 05:29:08: Counter=24
22.02.2019 05:29:08: Time=05:29:07
======================================
======================================
22.02.2019 05:44:08: Counter=25
22.02.2019 05:44:08: Time=05:44:07
======================================
======================================
22.02.2019 05:59:08: Counter=26
22.02.2019 05:59:08: Time=05:59:07
======================================
 

Attachments

  • testservicenew.zip
    9 KB · Views: 220
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
but if the device is turn-on the service doesn't start!

how it's the best solution?
 
Upvote 0
Top