My app has a service which starts during boot, and it needs to keep running. However, when I close my app by swiping it on the "Recent apps" screen, the service stops. To get around this, I used startForeground with a notification, and now my service keeps running even when I kill the app. My query is : how do apps like Facebook, Whatsapp, etc operate? They have services which keep running even when we kill the app, but I don't see any notification in the notification bar saying "Facebook is running" or "Whatsapp is running".
Starting in Android 13 (API level 33), users can dismiss the notification associated with a foreground service by default. To do so, users perform a swipe gesture on the notification.
setContentText("To hide me, click and uncheck \"Hidden Notification Service\"") . setContentIntent(pendingIntent) . setSmallIcon(R. mipmap.
Foreground services are an advanced Android concept which allows you to display notifications to your users when running long lived background tasks. The notification acts like any other notification, however it cannot be removed by the user and lives for the duration of the service.
It is just that the Apps and their component(such as Service) are being restarted as when they receive Push notifications, so that user can interact with the app. So, as and when Push notification is received (means WhatsApp message), Android can restart the killed app's component(in this case WhatsApp).
There is no officially supported way to keep a service running without a foreground notification (nor should there be). If there are any loopholes found to get around this, Google will surely (and has in the past) fix them, breaking any apps that are exploiting them.
I cannot say how exactly Facebook and Whatsapp work, but if you are asking how they notify the user of new messages in real-time, they are likely relying on Google Cloud Messaging (GCM) for push notifications, which does not require a service or your application to be constantly running.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With