Android Question Firebase push messages: first is auto-cancelled

peacemaker

Expert
Licensed User
Longtime User
HI, All

I know the pre-history that app in "STOPPED" stated cannot receive any pushes.
If app is started - pushes are received OK, any next.

But if to close it in the recent apps list - it's not fully stopped, event "fm_MessageArrived (Message As RemoteMessage)" is fired (and it makes a Notification), but the sound is momentally interrupted and the Notification is removed.

Second push message is the same arrived, but no problem with Notification - it exists and after tapping the needed activity is open OK.

Who also found ? Why and how to solve ?
 

KMatle

Expert
Licensed User
Longtime User
it's not fully stopped

The service starts automatically when a message arrives

is fired (and it makes a Notification), but the sound is momentally interrupted and the Notification is removed.

Without seeing your code: It looks like the app crashes at the time. Please check the logs (unfiltered) and see if there's a exception. If so, debug where it happens.
 
Upvote 0

tigrot

Well-Known Member
Licensed User
Longtime User
Maybe you refer an uninitialized object. The first time notification crashes, you init object and then the next notification is succesful. You should be sure everytime you execute the sub that every object is fully initialized. I had this issue in my last APP.
Ciao!
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
#Region  Service Attributes
    #StartAtBoot: True
#End Region

Sub Process_Globals
    Dim fm As FirebaseMessaging
    Dim Token As String
    Dim n As Notification
    Dim tim As Timer
End Sub

Sub Service_Create
    fm.Initialize("fm")
    tim.Initialize("tim", 2000)
    SubscribeToTopics
    tim.Enabled = True    'pause for getting the token, as sometimes it's empty returned

End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
 
    Dim title As String = Message.GetData.Get("title")
    Dim body As String = Message.GetData.Get("body")

Log(Message.GetData)    '(MyMap) {priority=high, vibration=1, body=Тело, sound=default, title=title, orderId=2033}
Dim requestId As String = Message.GetData.Get("requestId")
If requestId <> "" Then
    orders.CurOrderID = orderId
    orders.push = True
        If IsPaused(orders) Then
      
        Else
            CallSub(orders, "Activity_Resume")
        End If

        n.Initialize
        n.Icon = "icon"
        n.SetInfo(title, body, orders)
        n.Notify(1)
End If
End Sub

Sub Service_Destroy

End Sub

Sub fm_TokenRefresh
    Log("In Refresh " & $"Token(${fm.Token})"$)
    tim_Tick
End Sub

Sub tim_Tick
    Dim a As String = fm.Token
    If a <> "" Then
        Token = a
        tim.Enabled = False
    End If
    Log("In Service_Create " & $"Token(${fm.Token})"$)
End Sub

B4X:
  If pushIntent.HasExtra("orderId") Then
            Dim requestId As String = pushIntent.GetExtra("orderId")
            'Log("push from Main: " & orderId)
            If orderId <> "" Then
                orders.CurOrderID = orderId
                orders.push = True
                Dim tt As String = Starter.SQL.ExecQuerySingleResult("SELECT title FROM RequestList WHERE id = " & orderId & "'")
                orders.Title = tt.Replace("&quot;", QUOTE)
                StartActivity(orders)
            End If
        End If
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
It looks like the app crashes at the time. Please check the logs (unfiltered).

Seems, you are right. There is some error in the unfiltered log, but i cannot catch it - the log is very fastly overloaded and first log lines are cleared.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Ha, solved: there was another place where Notification with id=1 was cancelled.
But another trouble is found.
 
Last edited:
Upvote 0
Top