Android Question FireBase RuntimeException

ilan

Expert
Licensed User
Longtime User
hi

i am getting lately some crash reports in my console on android 8 in my firebase service.
i have followed the tutorial (how serviced are working in android 8) and also the firebase tutorial but still get those crashes. the weird thing is that i am not sending any push messages to the devices so it happens i guess on app start where i initialize firebase or something like that.

any ideas why i am getting it?

java.lang.RuntimeException:

at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3694)

at android.app.ActivityThread.-wrap21 (Unknown Source)

at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1801)

at android.os.Handler.dispatchMessage (Handler.java:105)

at android.os.Looper.loop (Looper.java:164)

at android.app.ActivityThread.main (ActivityThread.java:6938)

at java.lang.reflect.Method.invoke (Native Method)

at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:327)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1374)
Caused by: java.lang.IllegalStateException:

at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1538)

at android.app.ContextImpl.startService (ContextImpl.java:1484)

at android.content.ContextWrapper.startService (ContextWrapper.java:663)

at anywheresoftware.b4a.keywords.Common.StartService (Common.java:884)

at anywheresoftware.b4a.objects.ServiceHelper$StarterHelper.onStartCommand (ServiceHelper.java:211)

at www.sagital.mysalarynew.firebasemessaging.onStartCommand (firebasemessaging.java:69)

at android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3677)
 

ilan

Expert
Licensed User
Longtime User
A possible cause of this error is the usage of an old FirebaseNotifications.jar. Open the internal libraries folder and check the size of FirebaseNotifications.jar. It should be 9506 bytes.

ok, just checked and i have 8,836 byte

last date modified 22/1/2017

btw i have this in my starter Service_Create


B4X:
    Try
        CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'notification test
    Catch

       Log(LastException)
    End Try

and this is my FB Service:

B4X:
'FirebaseMessaging
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals   
   Private fm As FirebaseMessaging
End Sub

Sub Service_Create
   fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    Try
        If Starter.sendNotifaction Then fm.SubscribeToTopic("mysalarynew") 'you can subscribe to more topics
        fm.SubscribeToTopic("mysalarynewversion")
'        fm.SubscribeToTopic("mytests")   
'        fm.SubscribeToTopic("mytestsnew")   
    Catch
        Log(LastException)
    End Try
End Sub

Sub Service_Start (StartingIntent As Intent)
   If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
   Sleep(0)
   Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
        
    Try
        Dim title As String
        title = Message.GetData.Get("title")
        title = title.Replace(" ","")
        If title = "promo" Then
            Dim str() As String = Regex.Split("\|",Message.GetData.Get("body"))
            Starter.promolink = str(2) 
            Dim n As Notification
            n.Initialize
            n.AutoCancel = True
            n.Light = True
            n.Sound = False
            n.Vibrate = True
            n.Icon = "icon"           
            n.SetInfo(str(0), str(1), openlink)
            n.Notify(1)   
        else if title.Contains("newversion") Then 'new version
           Starter.promolink = "https://play.google.com/store/apps/details?id=www.sagital.mysalarynew"
           Dim n As Notification
           n.Initialize
           n.AutoCancel = True
           n.Light = True
           n.Sound = False
           n.Vibrate = True           
           n.Icon = "icon"
           n.SetInfo("יצא עדכון חדש לשכרניק", "יצא עדכון חדש, מומלץ לעדכן את שכרניק!", openlink)
           n.Notify(1)   
        Else
           Dim n As Notification
           n.Initialize
           n.AutoCancel = True
           n.Light = True
           n.Sound = False
           n.Vibrate = True           
           n.Icon = "icon"
           n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
           n.Notify(1)               
        End If       
    Catch
        Log(LastException)
    End Try
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
You are using an old version of FirebaseNotifications. You have probably copied it at some point to the internal libraries folder.

I recommend you to delete all internal libraries and reinstall B4A.

if i install b4a again will it not overwrite all old libraries?
how do i know what are all internal libraries? i have a lot 3rd party libraries.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
if i install b4a again will it not overwrite all old libraries?
yes, but maybe you did copied more to the internal libs folder and this should not be there....
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
sorry i did a mistake, i have copied by mistake the firebasenotification.jar to basic4android folder and not to libraries folder and this is the jar i checked that has 8836 but if i check in my basic4android/libraries folder i do see the jar in the correct size (9506)

i just deleted the false jar but i believe that b4a used the jar in the libraries folder that should be the right one.
 
Upvote 0
Top