I've created a new app, and added a service module with the following code:
In my Main I have put:
All I want is showing a message every 10 seconds, even when the app is not running (of course the 10 seconds is only a test).
When I start the app, the service starts and I can clearly see the message appearing every 10 seconds, even when the app itself is not active (when I'm at the homescreen for instance). However, as soon as I kill the app in Android, the service doesn't run anymore. I was expecting the service to continue to run since the service is started again with AtExact... so I'm probably not understanding something here... what am I missing?
B4X:
#Region Service Attributes
#StartAtBoot: True
#End Region
Sub Process_Globals
Dim Notif As Notification
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Notif.Initialize2(Notif.IMPORTANCE_DEFAULT)
Notif.Icon = "icon"
Notif.Sound = True
Notif.Light=True
Notif.Vibrate = True
Notif.AutoCancel=True
Notif.SetInfo2("MyTitle", "Mybody", "MyTag", Main)
Notif.Notify(9999)
Service.StartForeground(1,Notif)
Dim p As Period
p.Hours = 0
p.Minutes = 0
p.Seconds=10
Dim newDate As Long = DateUtils.AddPeriod(DateTime.Now, p)
StartServiceAtExact(Me,newDate,True)
Service.StopAutomaticForeground 'Call this when the background task completes (if there is one)
End Sub
Sub Service_Destroy
End Sub
In my Main I have put:
B4X:
StartService("service")
When I start the app, the service starts and I can clearly see the message appearing every 10 seconds, even when the app itself is not active (when I'm at the homescreen for instance). However, as soon as I kill the app in Android, the service doesn't run anymore. I was expecting the service to continue to run since the service is started again with AtExact... so I'm probably not understanding something here... what am I missing?