Android Question FCM store messages and show in customlistview

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime User
Hello
How's everybody?

I'm finishing a job with FCM
My question is, can you help me with an example of how to save the messages once received to show them in a Customlistview, whenever you need it.
What happens now is that when I left and re-entered I lost the messages.

Regards,
 

DonManfred

Expert
Licensed User
Longtime User
What is stopping you from saving the incoming message (topic and body) into a sqlite database?

You can then use the SQLite-Table to query the Niotifications and show them in a CLV...
 
Last edited:
Upvote 0

wes58

Active Member
Licensed User
Longtime User
Thank you very much for the suggestions.
I will try with SQLite How
I would like to have the knowledge that you have
I hope to make it regards
It also depends what you want to do with those messages. Are you going to search for a particular message, or just display all messages received.
If you are not going to do any sorting, searching for messages then you can simply do something like this.
B4X:
Sub Process_Globals
    Type FCMMsg( topic As String, body As String)
    Dim msgList As List
End Sub

Sub newFcmMsg(topic As String, body As String)
    Dim newMsg As FCMMsg
    newMsg.body = body
    newMsg.topic = topic
    If Not(msgList.IsInitialized) Then     'you can initialize the list somewhere else
        msgList.Initialize
    End If
    msgList.Add(newMsg)   
End Sub

Sub readMsg(index as Int)
    Dim msg As FCMMsg
    msg.Initialize
    msg = msgList.Get(index)
    Dim topic as String = msg.topic
    Dim body as String = msg.body
End Sub

You don't need any database for this.
When you get a new message call sub newFcmMsg to add it to the list. You can delete messages from the list. You can save the list to the file and access it any time.
 
Upvote 0
Top