Android Question Starter Service Crash / ANR

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I looked at my Google Crashes and ANRs and saw this entry

1726689145309.png


The ONLY service I have in my app is the Start Service.

I am not getting a lot of these crashes but some device must be having them.

NOT sure how to fix this. Below is a copy of my Starter

BobVal


Starter:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Private     logs                                     As StringBuilder
    Private     logcat                                     As LogCat

'    Private        mIsConnectedCalled                         As Boolean    = False
'    Private        mConnected                                As Boolean  = False

End Sub

Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    
    LogColor("Service_Create", Colors.Magenta)
    
'    If  IsDeviceFoldable = False Then
'    End If

#if NeedServiceReceiver
        If     HttpUtils2Service.TempFolder = "" Then
            Dim jo As JavaObject
        
            jo.InitializeNewInstance(Application.PackageName & ".httputils2service", Null)
            jo.RunMethod("onReceive", Array(Null, Null))
        End If
#end if       
End Sub



Sub Service_Start (StartingIntent As Intent)   
    
'    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
    
    logs.Initialize
            
    logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Private Sub logcat_LogCatData (Buffer() As Byte, Length As Int)
            logs.Append(BytesToString(Buffer, 0, Length, "utf8"))
            
            If     logs.Length > 5000 Then
                logs.Remove(0, logs.Length - 4000)
            End If
End Sub


'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Public  Sub Application_Error(Error As Exception, StackTrace As String) As Boolean

            LogColor($"Starter::Application_Error - Error:${Error.Message}"$, Colors.Red)
            
            return true
End Sub

Sub Service_Destroy
End Sub
 

drgottjr

Expert
Licensed User
Longtime User
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the question has been asked directly (in that same link) but not answered.
i would say the answer is yes.
i believe your options are either to remove the starter or to add a foreground
service type to it. shortService might work. that is to say it is a legal
type. whether google finds it applicable depends on what they see when
considering your app for publication. the starter service seems to perform a
very unique function which may or may not actually be thought of as a long-running
service (eg, mediaplayback) since it only runs at a given point in an activity's
lifecycle. what it does during the rest of the activity - if anything - is unclear
(to me). if it behaves like a broadcast receiver, go with shortService as its type.
 
Upvote 0
Top