Android Question Notification and startForegroundService error

asales

Expert
Licensed User
Longtime User
I get a crashlytics in Android 8
Context.startForegroundService() did not then call Service.startForeground()

probably with this code:
B4X:
'Alarm Service
Sub Service_Start (StartingIntent As Intent)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.AutoCancel = True
    n.Vibrate = False
    n.SetInfo2("You get a new message!", "Click and check it!", "odNotify", Main)
    n.Notify(1)
    
    Dim t As Long
    t = FindNextTime(Array As Double(8, 12, 18))
    
    StartServiceAt(Me,t,True)
    StopService(Me)
End Sub

I saw this tutorial from Erel:
https://www.b4x.com/android/forum/threads/automatic-foreground-mode.90546/#content

but I don't know how I can change the code above correctly, with this lines:
B4X:
Sleep(0) 'allow the MessageReceived event to be raised.
Service.StopAutomaticForeground
I can insert this lines in any part of the code? Or before StopService? Or after StopService?

Thanks in advance for any tip.

(B4A = 8 / SDK Target = 21)
 

asales

Expert
Licensed User
Longtime User
The code looks correct. Are you setting Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_NEVER ?
No. I only chance StopService to
StopAutomaticForeground and release the new version of the app. Until now I don't saw other logs in crashlytics from Android 8 with this issue. Let's see what happen. Thanks!
 
Upvote 0
Top