Android Question How to destroy FirebaseMessaging programmatically?

gacar

Active Member
B4X:
Private Sub CheckBoxUyari_CheckedChange(Checked As Boolean)
    If Checked Then
        KVS.Put("BildirimlerAcik", True)
        CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
    Else
        KVS.Put("BildirimlerAcik", False)
        CallSubDelayed(FirebaseMessaging, "Service_Destroy") '<====== here not firing if application still open. 
    End If
End Sub
 
Solution
I solved with this way

B4XMainPage
B4X:
Private Sub Timer1_Tick
    StartService(FirebaseMessaging)
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub

FirebaseMessaging
B4X:
Sub Service_Start (StartingIntent As Intent) 
    xui.SetDataFolder("kvs")
    KVS.Initialize(xui.DefaultFolder, "kvs.dat")
    If KVS.Get("BildirimlerAcik") Then
        If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
        Sleep(0)
        Service.StopAutomaticForeground 'remove if not using B4A v8+.
    Else
        StopService(Me) 
    End If
End Sub

SettingPage
B4X:
Private Sub CheckBoxUyari_CheckedChange(Checked As Boolean)
    xui.SetDataFolder("kvs")
    KVS.Initialize(xui.DefaultFolder, "kvs.dat")
    If...

DonManfred

Expert
Licensed User
Longtime User
Calling the sub Service_Destroy does not destroy anything. Put a log there. Guess you´ll see it in the LOG...
The sub is called by the system when the system destroys the service.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
What about unsubscribe topic?
 
Upvote 0

gacar

Active Member
I solved with this way

B4XMainPage
B4X:
Private Sub Timer1_Tick
    StartService(FirebaseMessaging)
    CallSubDelayed(FirebaseMessaging, "SubscribeToTopics")
End Sub

FirebaseMessaging
B4X:
Sub Service_Start (StartingIntent As Intent) 
    xui.SetDataFolder("kvs")
    KVS.Initialize(xui.DefaultFolder, "kvs.dat")
    If KVS.Get("BildirimlerAcik") Then
        If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
        Sleep(0)
        Service.StopAutomaticForeground 'remove if not using B4A v8+.
    Else
        StopService(Me) 
    End If
End Sub

SettingPage
B4X:
Private Sub CheckBoxUyari_CheckedChange(Checked As Boolean)
    xui.SetDataFolder("kvs")
    KVS.Initialize(xui.DefaultFolder, "kvs.dat")
    If Checked Then
        KVS.Put("BildirimlerAcik", True) 
    Else
        KVS.Put("BildirimlerAcik", False) 
    End If 
End Sub
 
Upvote 0
Solution
Top