I know services are covered alot on here and I have tried to follow the updated examples (Location Tracker etc) however I cannot understand why my app which sends simple notifications based on a list of times via a service will run fine every hour (or whatever interval I set) during the day however the next day the service doesn't fire anymore until I open the app again.
The FindNextSchedule part works fine, I've used the FindNextTime and SetHours examples from this forum and I can see in the log that the next scheduled time is always correct. From the main, I'm simply calling StartService(ServiceName) and this is my service:
B4X:
Sub Service_Start (StartingIntent As Intent)
Dim t = FindNextSchedule As Long 'will be 13:13, then 14:13 for example
Dim n As Notification
n.Initialize
n.Vibrate = True
n.AutoCancel = True
n.icon = "icon"
n.SetInfo("Test", DateTime.Time(DateTime.Now), Main)
n.Notify(1)
StartServiceAt(Me, t, True)
End Sub
I've tried using
Service.StopAutomaticForeground after the StartServiceAt call however that didn't seem to do anything. I don't want a persistent app icon/notification, just the one which is delivered by the service which will keep running as per its next scheduled run time. The custom service is StartAtBoot=False and has global variables, initially supplied the Main sub. Is what I'm wanting possible? Even when I tried it with StartAutomaticForeground and changed my phone time to the next day, the notification still didn't appear?
1. Make sure that it is not the starter service.
2. The interval should be larger than 30 minutes.
3. Check the logs (USB debug mode) and see whether Service_Create was called.