Android Question Correct way to set up Firebase Notifications and other services from boot

Num3

Active Member
Licensed User
Longtime User
Hello all,

For a long time i have used the trusted Starter service to setup all types of things when an app started, including initing Firebase Notifications, but since the change to receivers, which do not guarantee the starter service is running, things are not so simple .

So i would like to know if this is the correct way of initiating Firebase Notifications, after boot:

Of course the application is run if foreground prior to all this, so the user can give all necessary permissions before hand.

a) Create a receiver named FirebaseMessaging
b) Create a receiver named bootdone
c) Give correct permission on the manifest
B4X:
AddPermission (android.permission.RECEIVE_BOOT_COMPLETED)
AddReceiverText(bootdone, <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>)

d) on the bootdone file
B4X:
Sub Process_Globals
 
End Sub

'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
' Place mission critical setups here
If FirstTime then
 CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End If
End Sub

Other questions:
  1. Is it acceptable to call the Starter service from the boot receiver, or is it launched the first time the boot receiver code is run ?
  2. Is it ok to start a foreground service (i.e. permanent silent notification similar to "background location tracking example") from boot receiver?
  3. Is there a problem in "Subscribing to topics" from boot and later when the app is launched in foreground?
Thanks in advance.
 
Last edited:
Top