I'm running the Slack app on an Android 11 device. If the app is placed in the background by tapping on the device's home button and a Slack chat message arrives, it displays a notification on the Android notification bar. If you tap on the notification icon to open the notification and then tap on the message, the notification is removed.
What puzzles me is whether an app like Slack even uses a foreground service when receiving chat messages. From my experiencee, to have a continously running background service when no UI is shown, you must display a notification icon on Android's notification bar to indicate to the user that the app is running a background service. While this is considered a background service, it is in fact referred to as a foreground service.
But Slack does not display an icon on the Notification bar to indicate any foreground service. So if it's not using a foreground service but can receive messages while the UI is not shown and post a notification, how is this being done? Has something changed in Android that you don't need a foreground service in order to run a long running process in the background?
The only possible explanation I can think of is that instead of a service, a class that inherits from Application is used and the process for receiving messages is done within a coroutine that is launched from this class and remains active as long as the app remains alive. But if that is true, it means that apps CAN run endless background processes without any UI showing and that means that something changed in the policy required by Android to run endless background services.
CodePudding user response:
What puzzles me is whether an app like Slack even uses a foreground service when receiving chat messages
Most likely, they do not.
So if it's not using a foreground service but can receive messages while the UI is not shown and post a notification, how is this being done?
Most likely, on Google Play ecosystem devices, they are using Firebase Cloud Messaging (FCM) as a trigger to find out about messages that require user notification. FCM and its predecessors (C2DM and GCM) have been around for over a decade and are designed for this sort of problem.
CodePudding user response:
if you look at the firebase messaging documentation you will be understood notifications that arrived to a client are not handled by the application, there is an Android transport layer (ATL) that is responsible for getting messages even if application is not running!