I have a service which is set to execute every 30 seconds to perform a simple task, that is configured like this:
B4X:
Sub Service_Start (StartingIntent As Intent)
Try
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerSecond, False)
If StartingIntent.HasExtra("android.intent.extra.ALARM_COUNT") Then
.
.
.
The question is... if, for some reason, the execution takes more than 30 seconds, will a second instance of the server be fired before the previous one finishes? In case of yes, which would be the best-practice approach to avoid that (ie: to fire the new start 30 seconds after the previous one finishes)?
And with what do I have to check the StartingIntent, besides ALARM_COUNT, to check if the service was automatically started at boot? Because I imagine that if I put the StartServiceAt at the end, the StartingIntent.HasExtra("android.intent.extra.ALARM_COUNT") will be "False" at first start?
I solved this problem setting a global variable in my service (ImRunning = true), I check first Myservice.ImRunning before executing other. Do it's correct this approach?