Hi have a B4a B4XPages app and receive the following warning:
It is recommended to remove the Starter service in B4XPages projects. (warning #37)
The app uses Firebase Messaging and ShortcutBadger.
Manifest:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="35"/>
How do I remove the Starter service, but keep the original Starter functionality?
Starter:
It is recommended to remove the Starter service in B4XPages projects. (warning #37)
The app uses Firebase Messaging and ShortcutBadger.
Manifest:
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="35"/>
How do I remove the Starter service, but keep the original Starter functionality?
Starter:
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private Badge As ShortcutBadger
Private Analytics As FirebaseAnalytics
Private xui As XUI
Public IsLoading As Boolean
Private nid As Int = 1'***************************
End Sub
Sub Service_Create
IsLoading = True
Badge.Initialize()
Analytics.Initialize
If File.Exists(xui.DefaultFolder, modIS.DbaseLocal) = False Then
File.Copy(File.DirAssets, modIS.DbaseLocal, xui.DefaultFolder, modIS.DbaseLocal)
End If
modIS.SQLiteDB.Initialize(xui.DefaultFolder, modIS.DbaseLocal, True)
wait for (WeHaveAUser) Complete (Done As Boolean)
wait for (CountNotifications) Complete (Done As Boolean)
wait for (CountDevices) Complete (Done As Boolean)
UpdateAppBadge(modIS.BadgeNumber)
CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", "is")
End Sub
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
Service.StartForeground(nid, CreateNotification("iS-PROTECTOR is running"))
StartServiceAt(Me, DateTime.Now + 30 * DateTime.TicksPerMinute, True)
End Sub
Sub CreateNotification (Body As String) As Notification
Dim notification As Notification
notification.Initialize2(notification.IMPORTANCE_LOW)
notification.Icon = "Logo-IS-HP"
notification.SetInfo("iS-PROTECTOR", Body, Splash)
Return notification
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
End Sub
Sub WeHaveAUser As ResumableSub
'check if we a user in the db
Dim dbUser As B4XDBUtils
dbUser.Initialize(modIS.SQLiteDB, "user", "userid", "userid")
dbUser.SelectAll(Array("*"), Null)
'process the query
dbUser.FromJSON
If dbUser.affectedRows = 0 Then
modIS.MyProfile.Initialize
Return False
Else
modIS.MyProfile = dbUser.result.Get(0)
modIS.StartTime = modIS.myprofile.GetDefault("starttime", "")
modIS.endtime = modIS.myprofile.GetDefault("endtime", "")
If modIS.StartTime <> "" Then
modIS.iStartTime = modIS.MvField(modIS.StartTime,1, ":")
modIS.iStartTime = modIS.CInt(modIS.iStartTime)
End If
If modIS.EndTime <> "" Then
modIS.iEndTime = modIS.MvField(modIS.endtime,1, ":")
modIS.iEndTime = modIS.CInt(modIS.iEndTime)
End If
Return True
End If
End Sub
'notifications are local to this user
Sub CountNotifications As ResumableSub
Dim tbInbox As B4XDBUtils
tbInbox.Initialize(modIS.SQLiteDB, "inbox", "msgid", "msgid")
tbInbox.SelectAllAscDesc(Array("*"), Array("msgdate"), Array("msgdate"))
tbInbox.FromJSON
Dim notifTot As Int = tbInbox.result.Size
modIS.BadgeNumber= notifTot
Return True
End Sub
Sub CountDevices As ResumableSub
Dim tbInbox As B4XDBUtils
tbInbox.Initialize(modIS.SQLiteDB, "devices", "id", "id")
tbInbox.SelectAll(Array("*"), Array("devicename"))
tbInbox.FromJSON
Dim notifTot As Int = tbInbox.result.Size
modIS.DeviceNumber = notifTot
modIS.Devices.Initialize
'
For Each devicem As Map In tbInbox.result
Dim sdeviceid As String = devicem.GetDefault("deviceid", "")
Dim sdevicename As String = devicem.GetDefault("devicename", "")
'store the devices for later use
modIS.Devices.Put(sdeviceid, sdevicename)
CallSubDelayed2(FirebaseMessaging, "SubscribeToTopics", sdeviceid)
Next
Return True
End Sub
Sub UpdateAppBadge(bv As Int)
Try
If Badge.isInitialized Then
If bv = 0 Then
Badge.removeCount
Else
Badge.applyCount(bv)
End If
End If
Catch
Log(LastException)
End Try
End Sub