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

Discussion in 'Android Questions' started by lucad, Sep 12, 2018.

  1. lucad

    lucad Member Licensed 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

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Just remove the call to Sleep(0). It is not needed.
     
  3. lucad

    lucad Member Licensed 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 ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It is unlikely to be noticeable without the Sleep(0) call (the behavior will probably exactly the same).

    You can keep a single call. It doesn't matter which one.
     
  5. lucad

    lucad Member Licensed User

    perfect! thanks. I'll keep the first call because my delay is actually there, it' due to an http request
    Code:
    Wait For (j) JobDone(j As HttpJob)
                  
    If j.Success Then
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice