Android Question FireBaseService Sub not exists

Discussion in 'Android Questions' started by ilan, Jun 15, 2018.

  1. ilan

    ilan Expert Licensed 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

    Code:
    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:

    Code:
    '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(0As 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?

     
  2. ilan

    ilan Expert Licensed 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.
     
  3. ilan

    ilan Expert Licensed User

     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Open B4A Sdk Manager and update all recommended items. Note that if you are using FirebaseAuth then there is an issue with the latest version. You need to keep v15.1.0
     
    ilan likes this.
  5. ilan

    ilan Expert Licensed User

    Ok thank you i will do that :)
     
  6. ilan

    ilan Expert Licensed 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! :)
     
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