Android Question FireBaseService Sub not exists

ilan

Expert
Licensed User
Longtime User
hi

i have a lot firebase crashes and suddenly i think i know why.

making some simple tests gave me this:

on starter_create i am asking to subscribetotopics but it says the the sub doesnot exists

B4X:
Sub Service_Create
    logs.Initialize
    #if RELEASE
        logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
    #end if

    shared = rp.GetSafeDirDefaultExternal("shared")  
   
    If File.Exists(File.DirInternal,"userid.txt") Then
        userid = File.ReadString(File.DirInternal,"userid.txt")
    Else
        userid = createrandomuser(12)
        Log("userid: " & userid)
        File.WriteString(File.DirInternal,"userid.txt",userid)
    End If  
   
    Try
        If SubExists(FirebaseMessaging, "SubscribeToTopics") Then
            CallSubDelayed(FirebaseMessaging, "SubscribeToTopics") 'notification test
        Else
            Log("not exists")  
        End If
    Catch
        Log(LastException)
    End Try
End Sub

this is my firebaseservice:

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

Sub Process_Globals  
   Private fm As FirebaseMessaging
   Private Thread1 As Thread 'ignore
End Sub

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

Public Sub SubscribeToTopics
    Try
        Log("subscribe to topics called")
        fm.SubscribeToTopic("buysmartnew") 'you can subscribe to more topics
        fm.SubscribeToTopic(Starter.userid)
    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)
   
    Try
        Dim title As String
        title = Message.GetData.Get("title")
        title = title.Replace(" ","")
       
        If title.Contains("unsubscribe") Then 'new version
             Log("call unsubsribe to all topics")
             removeToken
        else if title = "chat" Then 'received chat message
            'do something              
        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

Public Sub removeToken
    Dim args(0) As Object
    Thread1.Name = "B4A Thread 1"
    Thread1.Start(Null, "ThreadSub1", args)
End Sub

Sub ThreadSub1 'ignore
    Dim jo As JavaObject
    Try
        jo = jo.InitializeStatic("com.google.firebase.iid.FirebaseInstanceId").RunMethod("getInstance", Null)
        jo.RunMethod("deleteInstanceId", Null)
    Catch
        Log(LastException)
    End Try
End Sub

Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread
    If Not(fail) Then
        Log ($"Thread1 Ended with error : ${error}"$)
    Else
        Log ("Thread1 Ended without error")
        Sleep(1000)
        SubscribeToTopics
    End If
End Sub

why do i get FALSE in logs?

*** Service (starter) Create ***
not exists
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (starter) Destroy (ignored)**
 

ilan

Expert
Licensed User
Longtime User
ok ignore my first question i know why i get FALSE. the service is in the background and CallSubDelayed starts the service and then called the sub so i cannot check if a sub exists if the module is in the background but even if i remove the if sub exists the service doesn't starts always when the starter service is created.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Logger connected to: ce031713a972c8c80c
--------- beginning of crash
--------- beginning of main
--------- beginning of system
Copying updated assets files (53)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
subscribe to topics called
java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/www.sagital.buysmart-B1RDONhbaUGJu61RCGI23w==/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at www.sagital.buysmart.firebasemessaging._subtotopics(firebasemessaging.java:342)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
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)
java.lang.RuntimeException: java.lang.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/www.sagital.buysmart-B1RDONhbaUGJu61RCGI23w==/base.apk)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:175)
at anywheresoftware.b4a.BA$2.run(BA.java:365)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
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.NoSuchMethodError: No virtual method subscribeToTopic(Ljava/lang/String;)Lcom/google/android/gms/tasks/Task; in class Lcom/google/firebase/messaging/FirebaseMessaging; or its super classes (declaration of 'com.google.firebase.messaging.FirebaseMessaging' appears in /data/app/www.sagital.buysmart-B1RDONhbaUGJu61RCGI23w==/base.apk)
at anywheresoftware.b4a.objects.FirebaseNotificationsService$FirebaseMessageWrapper.SubscribeToTopic(FirebaseNotificationsService.java:130)
at www.sagital.buysmart.firebasemessaging._subtotopics(firebasemessaging.java:342)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
... 8 more
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
ok after updating the recommended packages from the sdk manager everything runs fine. thank you so much erel for your awesome support! :)
best support i have ever seen! :)
 
Upvote 0
Top