Hi all,
I created a small app which I use to send notifications to users.
My idea is that after notification is received I store it in a database so user can access it all the time.
Notifications is sent from same application but sending feature is "hidden" and protected so only I know how to send a message.
Everything works fine except when application is not running.
When I send notification, it arrives to another phone and I CAN see it and read it but it is not saved in DB.
In all other cases (when app is started) I can save the message.
This is what happens in log after I click on notification if application is closed:
I guess that problem is because Activity_Resume starts before firebasemessaging but I don't know how to fix it.
and here is FirebaseMessaging Service code
Can someone help me to fix this, please
Thanks
I created a small app which I use to send notifications to users.
My idea is that after notification is received I store it in a database so user can access it all the time.
Notifications is sent from same application but sending feature is "hidden" and protected so only I know how to send a message.
Everything works fine except when application is not running.
When I send notification, it arrives to another phone and I CAN see it and read it but it is not saved in DB.
In all other cases (when app is started) I can save the message.
This is what happens in log after I click on notification if application is closed:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
/storage/emulated/0/Android/data/com.vitka.FloorFitness/files
** Activity (main) Resume **
Main-Resume - poruka upisana prije: false
Main-Resume - poruka upisana poslije: false
*** Service (firebasemessaging) Create ***
** Service (firebasemessaging) Start **
'HERE SHOULD BE "Message arrived" LOG ENTRY but it's not if app is closed
I guess that problem is because Activity_Resume starts before firebasemessaging but I don't know how to fix it.
and here is FirebaseMessaging Service code
B4X:
#Region Service Attributes
#StartAtBoot: False
#End Region
Sub Process_Globals
Private fm As FirebaseMessaging
' Dim var As String
Dim varTitle, varBody As String
Dim dbS As SQL
Dim ruta As String
End Sub
Sub Service_Create
fm.Initialize("fm")
End Sub
Public Sub SubscribeToTopics
fm.SubscribeToTopic("floor") 'you can subscribe to more topics
End Sub
Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return
End Sub
Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
If File.ExternalWritable Then
ruta = File.DirDefaultExternal
Else
ruta = File.DirInternal
End If
Log($"Message data: ${Message.GetData}"$)
dbS.Initialize(ruta, "FloorFitness.db", True)
dbS.ExecNonQuery2("INSERT INTO messages VALUES (?, ?, ?, ?, ?)", Array As Object(Null, DateTime.Date(DateTime.Now),Message.GetData.Get("title"),Message.GetData.Get("body"), "0"))
' Main.porukaUpisana = True
Dim n As Notification
n.Initialize
n.Icon = "icon"
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)'Otvara Main activity
n.Notify(1)
Log("Poruka upisana u bazu Arrvd")
' n. Main.varTitle = Message.GetData.Get("title")
End Sub
Sub Service_Destroy
End Sub
Can someone help me to fix this, please
Thanks
Last edited: