Android Question Service runs throughout the day but doesn't run the next day

andyr00d

Member
Licensed User
Longtime User
Hello,

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

Referring to the post here:
https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546/

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?
 
Top