Android Question #StartAtBoot: True doesnt seem to work

Kevin Hartin

Member
Licensed User
I have a php web server that happily sends Firebase Push Notifications when a new record is created for a particular customer. These appear when the Android app has been started manually, allowing clients to know when there is something demanding their attention, as the clicking of the notification opens the app and it then updates andy missing records from the web server.

I created the following Service in the App called FirebaseMessaging, as per the tutorial. Originally #StartAtBoot was set to False, but I changed it to True in the hope that when the phone restarts any new notifications will be received without the App being started.

Am I missing something with this whole concept? I figure it needs to run like the Gmail app, getting push notifications irrespective of the app being opened manually.

Thanks,
Kev

B4X:
#Region  Service Attributes 
    #StartAtBoot: True
   
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic(Starter.VendorKey) 'you can subscribe to more topics
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)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n.Notify(1)
End Sub

Sub Service_Destroy

End Sub
 

Erel

Administrator
Staff member
Licensed User
Am I missing something with this whole concept?
Yes. The app doesn't need to run in order to receive notifications.

If you are not receiving notifications when your app is not running (don't kill it yourself as it is a different state) then go back to the tutorial and send the messages with the B4J code. Once you get it working you can switch to your PHP code.
 
Top