Android Question Notification service and Service.StopAutomaticForeground : App icon popup

lucad

Member
Licensed User
Longtime User
When the service is called from background to foreground, I can see the application Icon popping up into the upper notification area. It remains visible until the service code is completed ( until the Service.StopAutomaticForeground is called ) . This flashing icon can be annoying as it comes up even when there is nothing to be notified.

I think I resolved the issue calling the Service.StopAutomaticForeground almost at the beginning of the service code. I have noticed the code of the service is anyway executed till the end with no problems.

Someone knows if this is correct or if it can cause problems ?
See the code as it is now here below.
Thanks

B4X:
Sub Service_Create
    Service.AutomaticForegroundMode=Service.AUTOMATIC_FOREGROUND_ALWAYS  '26+
End Sub

Sub Service_Start (StartingIntent As Intent)
    Dim sec As Long = 1800
    Dim dnext As Long = DateTime.Now + (sec * DateTime.TicksPerSecond) ' prossima chiamata
     StartServiceAt(Me, dnext, True)                                         'schedule
       If StartingIntent.IsInitialized=True Then
            ' do something
          Try
            If StartingIntent.HasExtra("android.intent.extra.ALARM_COUNT") Then     
                
                    Service.StopAutomaticForeground    ' <--------- HERE!!???
                   ' Do something , it takes a while
            End If
              
          Catch
        
          End Try
    
        End If
     
    Sleep(0)
    Service.StopAutomaticForeground        ' da Android target +26

End Sub
 

lucad

Member
Licensed User
Longtime User
Removed, thank you, however I have to keep the Service.StopAutomaticForeground at the beginning of the service or the icon will pop up anyway.
Is it correct ?
 
Upvote 0

lucad

Member
Licensed User
Longtime User
perfect! thanks. I'll keep the first call because my delay is actually there, it' due to an http request
B4X:
 Wait For (j) JobDone(j As HttpJob)
              If j.Success Then
 
Upvote 0
Top