Android Question Notification error

pliroforikos

Active Member
Licensed User
Hello eveybody

I have a problem when receiving notifications to my app.
When it is open everything works ok and notifications comming and show as it is expected.

But when app closed/killed i see in the log file that message arrived but error occured and nothing showing on android screen. Tried in several mobiles.

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    
    n.Initialize
    n.Initialize2(n.IMPORTANCE_DEFAULT)
    n.Icon = "icon"
    n.OnGoingEvent = False
    'n.Sound = True
    n.AutoCancel = True
    
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    
    B4XPages.MainPage.BadgeNumber = B4XPages.MainPage.BadgeNumber + 1
    n.Notify(1)
    msgs = msgs + 1
    
    B4XPages.MainPage.reloadSystemMenu(B4XPages.MainPage.BadgeNumber)
    
End Sub

Any idea? Thanks in advanced...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Error is expected.
If your app wasn't running when the message was received, then the FirebaseMessasingService will start. At this point the main activity wasn't started so you cannot access B4XPages.
You can check it with:
B4X:
If B4XPages.IsInitialized = False Then
 'no pages
If the number is important then store it with KVS (or any other way) and read it in B4XPage_Created of B4XMainPage.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…