Android Question SDK 34 - B4XPage - Notifications

yiankos1

Well-Known Member
Licensed User
Longtime User
Good morning forum,

If i do the following procedure, i have a problem with notification and B4XPages initilization.

1) I open my app and click back button in order to exit app
2) I clear recent apps
3) When i send a notification and clicking it, log stops there:
B4X:
*** Receiver (firebasemessaging) Receive (first time) ***
Message arrived
Message data: {chatMessageID=d2dac0b7-263b-af8a-837c-4392e617fc75, chatID=132c703f-6f34-11ee-a7a2-52894e2c9ee7, typeNotification=chat, userTo=169097122283136, userSent=2dcc00c6-4da4-11ee-a7fa-52894e2c9ee7, body=S, title=ΕΠΩΝΥΜΟ ΟΝΟΜΑ}
** Service (starter) Start **
App is shown to be loaded but nothing loaded, just a black screen. Nothing from B4XPages loaded. I initialize nothing on starter service.

B4X:
Sub Activity_Resume
    B4XPages.Delegate.Activity_Resume
 
    Dim in As Intent
    in = Activity.GetStartingIntent
    If in.HasExtra("Notification_Tag") Then
        Log(in.GetExtra("Notification_Tag")) 'Will log the tag
 
        Dim jp As JSONParser
        jp.Initialize(in.GetExtra("Notification_Tag"))
        Dim root As Map = jp.NextObject
        Dim typeNotification As String = root.Get("typeNotification")
 
        Select typeNotification
            Case "changeSubNember"
                B4XPages.MainPage.tabMenu_TabClick(1)
            Case "chat"
                Dim userSent As String = root.Get("userSent")
        
                B4XPages.ShowPage("chatPage")
        
                B4XPages.MainPage.chatPage.getChat(userSent)
        End Select
 
    End If
End Sub

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)

    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    If B4XPages.IsInitialized And B4XPages.GetManager.IsForeground Then
        Log("App is in the foreground. In iOS a notification will not appear while the app is in the foreground (unless UserNotificationCenter is used).")
    End If
 
    Dim jgen As JSONGenerator
    jgen.Initialize(mapParameters)
    If B4XPages.IsInitialized Then
        If B4XPages.GetManager.GetTopPage.Title.As(String)=Message.GetData.Get("chatID").As(String) Then
            B4XPages.MainPage.chatPage.getLastChatMessage(Message.GetData.Get("chatMessageID"))
        Else
            Dim n As Notification
            n.Initialize2(n.IMPORTANCE_HIGH)
            n.AutoCancel=True
            n.Icon = "icon"
'            n.Number=1
            n.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString,Main)
            n.Notify(1)
        End If
    Else
        Dim n As Notification
        n.Initialize2(n.IMPORTANCE_HIGH)
        n.AutoCancel=True
        n.Icon = "icon"
        n.Number=1
        n.SetInfo2(Message.GetData.Get("title"), Message.GetData.Get("body"), jgen.ToString,Main)
        n.Notify(1)
    End If
End Sub

I can reproduce this behavior on Pixel 7 Pro (SDK 34). On an older smartphone, everything works fine.

p.s. It had been asked here too
 
Last edited:
Solution
Things to try to further debug:
- Don't kill the app with a swipe. Maybe it leaves it in an invalid state. You can restart the device for a clean test. You can also force stop it from the settings app.
- Remove the starter service.

yiankos1

Well-Known Member
Licensed User
Longtime User
What causes the starter service to start? The receiver will not start it?

The activity isn't supposed to become visible when the notification is received.
Hello Erel,

Starter service starts when i click the notification. And then, happens this: App is shown to be loaded but nothing loaded, just a black screen. Nothing from B4XPages loaded. I attach you a video to understand this behavior. This happens only at my pixel 7 pro with latest sdk
 
Last edited:
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
You wrote that it happens when you send a message. This is not the same as clicking on the notification.
I am sorry for this.
Does it make any different if you comment the additional code that you added in Activity_Resume?
Exactly the same behavior with this smartphone. I don't know if its a bug, but main page never triggered. Proccess stops at ** Service (starter) Start **
Moreover, as you can see at video, back button is disabled when you enter at this "stage". You can just minimize it in order to exit app.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
- Remove the starter service.
Removing starter service indeed did the trick... I can't figure out why this service causes this problem at sdk 34. Thank you once again Erel. Stay safe...
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Since the Starter service is a default item for a new project and its presence has been a constant in apps since many releases ago, this sudden removal comes as a surprise.
I also did not understood under which conditions it should not be used anymore.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…