I have a Main activity that calls a StartServiceAt. That service, if it detects that Main is paused, runs StartActivity(Main).
However, if the service is in the background, Main never gets started. I have new Android 10 mobile. It worked fine on old Android 9 mobile.
I've seen several posts on the problems with Android 10 and background services, how my app service needs to be foreground to start any other activity, and I have read the 'services lifecycle on android 8+', but still no go.
For testing, I create a timer then hit the Home button on my mobile so the app goes into background
[CODE lang="b4x" title="StartServiceAt"]StartServiceAtExact(ReminderService, dtNextTimer, True)[/CODE]
This successfully triggers ReminderService at the appointed time.
[CODE lang="b4x" title="Service_Start"]Sub Service_Start (StartingIntent As Intent)
Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_ALWAYS
If IsPaused(Main) Then
' Wake phone up (so can show timers)
Dim pws As PhoneWakeState
pws.KeepAlive(True)
pws.ReleaseKeepAlive
StartActivity(Main) 'force into foreground/resume
Else
CallSub(Main, "UpdateTimers")
End If
'Service.StopAutomaticForeground
StopService(Me)
End Sub[/CODE]
This runs successfully, finds Main is paused, tries to wake the phone (not relevant to this issue), then should start Main.
From what I have read, by default the service will be Service.AUTOMATIC_FOREGROUND_WHEN_NEEDED so it should have become foreground, and so it should have been able to start Main. I tried forcing it Service.AUTOMATIC_FOREGROUND_ALWAYS but no change.