Android Question Solution for android.app.RemoteServiceException ?

Powie

Member
Licensed User
Longtime User
Maybee someone has an idea. Since I have set targetSdkVersion="26" i got reported this Bug in the developer console:

B4X:
android.app.RemoteServiceException:
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2101)
at android.os.Handler.dispatchMessage (Handler.java:108)
at android.os.Looper.loop (Looper.java:166)
at android.app.ActivityThread.main (ActivityThread.java:7425)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)

For me it's a phantom, because I cannot reproduce this error on my devices.... If i search the forum, i find some hints thats this maybee is related to notifications.
Also my latest try, to disable the service who uses the notification system, doesnt helps me...

At this time, I have no idea how to handle this problem. Maybee it is related to some special cases or combinations of devices and Android 8.

In the Developer console it shows me, that this error only exists on Android 8 and it is showy often on Xperia Devices... This doesnt match to the distribution of the app over devices / android versions.....

madb-bug-1.JPG


How can I go the right way to solve this?
 

Powie

Member
Licensed User
Longtime User
Manfred.... I don't know which b4a code produces this error. that's my problem! If i run this app with debugger on my devices all is fine.

Is there a way to come from the numbers above to the b4a code.... (1881)
 
Upvote 0

Powie

Member
Licensed User
Longtime User
Theres no file long enough to reach 1881........

i got no more informations form the play console as shown here :cool:
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Theres no file long enough to reach 1881........
as i mentioned before: you need to check the complete stacktrace to find out the module... The stacktrace seems to be incomplete.

I suggest to add Crashlytics to your app. You´ll get the Stacktrace in the Firebase console (per email).

Aufnahme1.jpg
 
Upvote 0

Powie

Member
Licensed User
Longtime User
So........ there are no more infos available for me with Crashlytics. Its the same as in the Play Console......


But, it helps me to find out that this device produces this failure every 30 minutes, and thats exactly the interval of the service.....
Maybee it isnt a problem of the notification, as I understand that my service creates a notification if the service is startet in background.......
I have read some things an also tryed to change the icon for this notification, but at last it doesnt helps.....

Interessant ist aber:
Context.startForegroundService() did not then call Service.startForeground()
android.app.ActivityThread.main

madb-bug-2.JPG
 
Upvote 0

Powie

Member
Licensed User
Longtime User
Yes, I have read this more than once to understand the difference in running services on Android 8. First I was on the way for the generated notification....

The Service is started in 2 ways for the first time:
-> #StartAtBoot: true
-> StartService(finder) -> If the App is started, (FirstTime = true)

after that with StartServiceAt

However, it's not comprehensibly with my devices, had it on the debug for more than 24 hours..... And...... this happens for < 1% of all installations.....

Maybee I can find something in my service module.....
 
Upvote 0

Powie

Member
Licensed User
Longtime User
Story continues......

There are some more reports available in Crashlytics now. After more than 12 hours, the error is only at ca. 0.02 % of the devices, so I can count the useres with this error....
Additionally, Crashlytics reports me an error out of a Try .. Catch block... For this error I can find the line in the generated .java file. This error ist for all users at the same line.

At each user, the error android.app.RemoteServiceException is at a different line number..... So I think it occours not inside my code.

No idea at this time..........

The Service
B4X:
#Region  Service Attributes
    #StartAtBoot: true
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim myWifi As ABWifi
    Dim MyLocation As Location
    Dim MySQL As SQL
    Dim n As Notification
    Dim GPSf As GPS
    Dim GpsTimer As Timer
    Dim ScanTime As Int = 0
    Private rp As RuntimePermissions
    Dim sNotif As Notification
    Dim madbicon As Bitmap
    Dim sn As NB6
End Sub

Sub Service_Create
    madbicon = LoadBitmapResize(File.DirAssets, "nicon.png", 24dip, 24dip, False)
    'sn.Initialize("default", Application.LabelName, "LOW").AutoCancel(True).SmallIcon(madbicon)
    'sNotif = sn.Build(Application.LabelName, madb.lStrings.Get("search") & "...", Null, Main)
    'sNotif.Initialize
    'sNotif.Vibrate = False
    'sNotif.Light = False
    'sNotif.Sound = False
    'sNotif.Icon = "icon"
    'sNotif.SetInfo(Application.LabelName, madb.lStrings.Get("search") & "...", Main)
    'Service.AutomaticForegroundNotification = sNotif
    madb.InitLanguage
    madb.InitDBs
    MySQL.Initialize(File.DirInternal, "madb.s3db", False)
    MyLocation.Initialize
    If madb.SetupGetValue("finderenabled","true") = "false" And madb.FinderOneRun = 0 Then
        Service.StopAutomaticForeground
        StopService(Me)
    End If
    Log("LastVisit: " & madb.SetupGetValue("lastvisit",DateTime.Now))
    Log("LastVisited Field: " & madb.SetupGetValue("lastvisitedfield","none"))
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.AutomaticForegroundMode = Service.AUTOMATIC_FOREGROUND_WHEN_NEEDED
    n.Cancel(1)
    If rp.Check(rp.PERMISSION_ACCESS_FINE_LOCATION) Then
        GPSf.Initialize("GPS")
        GpsTimer.Initialize("timer1", 1000)
        ScanTime = 0
        Log("Scanne Visit")
        'StartServiceAt("", DateTime.Now + 60 * DateTime.TicksPerMinute, True)
        If GPSf.GPSEnabled = False Then
            Log("Scanne mit Netzwerkzellen/WIFI")
            'ToastMessageShow("Please enable the GPS device.", True)
            'StartActivity(GPS1.LocationSettingsIntent)       'Will open the relevant settings screen.
            Dim r As Boolean
               r = myWifi.ABGetLocation("myWifi")   
            'r = myWifi.GetLastKnownLocation("myWifi")   
               If r = False Then
                GPSf.Stop
                Service.StopAutomaticForeground
                StopService(Me)
            Else
                '
            End If
        Else
            Log("Scanne mit GPS")
            GpsTimer.Enabled = True
            'GPSf.Start(1000, 0) 'Listen to GPS with no filters.
        End If
        'wieder starten im nächsten Intervall
        StartServiceAt("", DateTime.Now + ( madb.FinderRescanMinutes * DateTime.TicksPerMinute) , False)
        'StartServiceAt("", DateTime.Now + ( 1 * DateTime.TicksPerMinute) , False)
        madb.FinderOneRun = 0
    Else
        Service.StopAutomaticForeground
        StopService(Me)
    End If
    Service.StopAutomaticForeground
End Sub

Sub Service_Destroy
    GPSf.Stop
End Sub

Sub myWifi_FoundLocation ()
   Dim ResLocation As ABFoundLocation
   ResLocation = myWifi.ABGetFoundLocation()
   MyLocation.Latitude = ResLocation.Latitude
   MyLocation.Longitude = ResLocation.Longitude
   madb.MyLocation = MyLocation
   FindField ( MyLocation )
End Sub

Sub FindField ( Loc As Location ) As String
    'Umfeld
    Dim fLat As Float
    Dim tLat As Float
    Dim fLong As Float
    Dim tlong As Float
    Dim MyLat As Float
    Dim MyLong As Float
    Dim Cursor1 As Cursor
    
    MyLat = NumberFormat(Loc.Latitude,0,6)
    MyLong = NumberFormat(Loc.Longitude,0,6)
    
    fLat = MyLat - 0.004
    tLat = MyLat + 0.004
    fLong = MyLong - 0.004
    tlong = MyLong + 0.004
    'sql   
    Cursor1 = MySQL.ExecQuery("SELECT * FROM airfields Where Latitude between " & fLat & " and " & tLat & _
                             " and Longitude between " & fLong & " and " & tlong & " Order By name" )
    'go
    Log("Finder found: " & Cursor1.RowCount)
    If Cursor1.RowCount = 1 Then
        Cursor1.Position = 0
        'Checke ob selber platz innerhalb 10 Stunden
        If madb.SetupGetValue("lastvisitedfield","0") = Cursor1.GetString("id") And madb.SetupGetValue("lastvisit", 0 ) > ( DateTime.Now - (DateTime.TicksPerHour * 10)) Then
            Log("Always logged")
            Service.StopAutomaticForeground
            StopService(Me)
        Else
            'n.Initialize
            'n.Icon = "icon"
            'n.Sound = True
            'n.Vibrate = False
            'n.Light = True
            'n.AutoCancel = True
            'n.SetInfo2(madb.lStrings.Get("field_visit_notification"),Cursor1.GetString("name"),Cursor1.GetString("id"),field)
            'n.Notify(1)
            'Notification new mit NB6
            Dim noti As NB6
            'madbicon = LoadBitmapResize(File.DirAssets, "nicon.png", 24dip, 24dip, False)
            noti.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(madbicon)
            n = noti.Build(Cursor1.GetString("name"), madb.lStrings.Get("field_visit_notification"), Cursor1.GetString("id"), field)
            n.Notify(1)
            'merken
            madb.SetupSaveValue("lastvisit",DateTime.Now)
            madb.SetupSaveValue("lastvisitedfield",Cursor1.GetString("id"))
            madb.SetupSaveValue("lastvisitedname",Cursor1.GetString("name"))
            Log("Visit Notification erzeugt")
            Service.StopAutomaticForeground
            StopService(Me)
        End If
    Else
        Service.StopAutomaticForeground
        StopService(Me)
    End If
    Cursor1.Close
End Sub

Sub GPS_LocationChanged (Location1 As Location)
    MyLocation = Location1
    GPSf.Stop
    madb.MyLocation = MyLocation
    Log("GPS Standort gefunden")
    FindField ( MyLocation )
End Sub

Sub timer1_tick
    ScanTime = ScanTime + 1
    Log("Finder: " & ScanTime)
    If ScanTime > madb.FinderTryGPSSeconds  Then
        GPSf.Stop
        GpsTimer.Enabled = False
        ScanTime = 0
        Dim r As Boolean
        Log("Kein GPS gefunden, versuche Netzwerkstandort")
           r = myWifi.ABGetLocation("myWifi")   
        'r = myWifi.GetLastKnownLocation("myWifi")   
           If r = False Then
            Service.StopAutomaticForeground
            StopService(Me)
        Else
            'StopService(Me)
        End If
    End If
End Sub

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

Powie

Member
Licensed User
Longtime User
Update. Some more Reports are available now in Crashlytics. It seems it's a problem of special devices.....

Same Devices reports the crash at the same linenumber.....

Example:

Galaxy S7 - Line 1881
Xperia X Compact - Line 1783

etc.
 
Upvote 0

Powie

Member
Licensed User
Longtime User
The starter service should never be explicitly started. Use a different service for a service that starts at boot (or started in any other way).

That's not the starter service. This service is called "finder"
 
Upvote 0
Top