Ad

How To Notify The User Who Closed Android App?

I'm trying to notify the user of my application about some changes in Firebase real-time database. It is always important for me to do this, even when the application is in the background or has been force stopped.

My first decision was to start the background service - startForeground(), but in this case the uninstalled notification “Application is running in the background” appears, so I refused it.

The second attempt was to work with Firebase Cloud Messaging, but as far as I understood this mechanism would only allow sending notifications. But how can I programmatically handle events and create notifications? Please show me an example or a way to work with FCM or a more elegant solution, if it helps me to complete the task.

Ad

Answer

To be able to receive messages when the user is not actively using your app, your best bet is to send a message through Firebase Cloud Messaging (FCM).

FCM supports two types of messages: Notification Messages that are usually displayed to the user, and Data Messages that are handled in your application code.

To send messages through Firebase Cloud Messaging that your application code can handle, send data messages as explained here.

Ad
source: stackoverflow.com
Ad