Android Question B4XPages and Push Notifications 2023+

Andie

Member
Licensed User
Longtime User
see Erel's tutorial: https://www.b4x.com/android/forum/threads/b4x-firebase-push-notifications-2023.148715/

My app is based on the PushClient example given in Erel's tutorial above.

When a new message arrives, I get the data from it via Sub fm_MessageArrived. I extended the example code a little bit: The incoming data is now stored in a string variable, which is displayed in a webview (could be a label, too) by calling the Sub B4XPages_appear, which is part of the module "B4XMainPage".

When the app is in the foreground or background, everything is fine. I can see the incomming text either at once (when the app was in the foreground) or by clicking on the notification (when the app was in the background). So far, so good.

But what can I do in case, the app hasn't been started yet, i.e. it's neither in the background nor in the foreground? The Sub fm_MessageArrived will be executed as well, but I cannot call the Sub B4XPages_appear, because B4XPages hasn't been initialized so far.
 

Andie

Member
Licensed User
Longtime User
The solution is:
Don't use CallSub(B4XPages.MainPage, "b4xPage_appear"), when the app hasn't been started yet.
Fortunately, there is no need to use CallSub(..., ...) in this case. Because of n.SetInfo(...., ...., Main) [n is the notification variable] the activity Main starts when the user hits the incoming notification.
 
Upvote 0
Top