Reputation: 441
I'm implementing chat in my app for my students. I'm using Room Database to store the chat messages. The problem now is when I want to delete a chat message for all recipients.
I'm using FCM to delete a message from Room Database for every recipients. The problem is when the app is not running, FCM has no way to pass the code (using EventBus) to Activity to delete a row (or flag a row) in Room Database. The best way it can do is to send a Notification. But it doesn't make sense to send a notification when someone's deleting a message.
I notice in WA or other chat apps, the recipients' chat message got deleted when someone is doing "Deleting for Everyone" for a specific chat message. What is the trick to achieve that?
Upvotes: 3
Views: 826
Reputation: 20197
As written: no. Room runs within the app, therefore it cannot do anything when the app is not running at all (that is, when the app does not have any living processes).
However, you are mistaken that something needs to happen in an Activity
to do something with Room. You could send an FCM data message and run Room code in the background in your onMessageReceived
callback. In that sense, the app is "not running" in that it's not open, but is instead running in the background.
You likely want to do this for all your database work and simply have the Activity listen for changes to the database, rather than trying to have the Activity itself make the database (since the Activity may not always be running).
Upvotes: 2