Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do Android apps like Facebook, Whatsapp have services in foreground without notification?

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".

like image 201
Karan Avatar asked Jan 08 '14 21:01

Karan


People also ask

How do you stop a foreground service?

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.

How do I hide foreground notifications?

setContentText("To hide me, click and uncheck \"Hidden Notification Service\"") . setContentIntent(pendingIntent) . setSmallIcon(R. mipmap.

What is a foreground notification?

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.

How does WhatsApp work in background?

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).


1 Answers

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.

like image 138
Yjay Avatar answered Sep 25 '22 09:09

Yjay