I want to start a foreground service that doesn't show notification,
apps like instagram, telegram, zapya, ... have a foreground service and they show no notifications.
I have tested ways like answers
here, but android shows a notification that yourAppName is running
.
I want to know how is that possible to have a foreground service with no notification or warning from OS?
Asked
Active
Viewed 6,575 times
4

Community
- 1
- 1

Mahdi-Malv
- 16,677
- 10
- 70
- 117
-
You are asking for alive service or foreground service? – Rahul Mar 21 '17 at 17:23
-
@Rasi a forground service. – Mahdi-Malv Mar 21 '17 at 17:38
-
1So according to link which you shared, Accepted answer suggest. O.S. avoid foreground services without notification – Rahul Mar 21 '17 at 17:45
-
Agreed. but how app like zapya, instagram, telegram etc. have sth like that? Is that sth else? – Mahdi-Malv Mar 21 '17 at 17:58
-
Possible duplicate of [How to startForeground() without showing notification?](http://stackoverflow.com/questions/10962418/how-to-startforeground-without-showing-notification) – Sam Apr 14 '17 at 03:33
-
I know you acknowledged the other question about this, but this is really an exact duplicate of that question. If one of the answers on the other question doesn't work for you, try leaving a comment or using a different answer. – Sam Apr 14 '17 at 03:34
-
Also, how did you determine that the apps you mentioned are running foreground services? – Sam Apr 14 '17 at 03:37
-
@Sam If you check running apps in android settings you can see some services from mentioned apps and no notification ofcourse. – Mahdi-Malv Apr 20 '17 at 06:42
-
@Skillson, I might be wrong, but I thought background services showed there as well? I believe [this method](http://stackoverflow.com/questions/10962418/how-to-startforeground-without-showing-notification#comment14757950_11076012) it a very accurate way to determine if a service has requested to run in the foreground. – Sam Apr 20 '17 at 23:00
-
@Sam What i want is a service to count time all the time and pause and restart when i needed and i do not need notification. Do you suggest `intent services`? – Mahdi-Malv Apr 23 '17 at 07:11
-
1Hmm, it's hard to say. Having a foreground service running in the background just to count time sounds like a waste of resources to me. Could you just store a running total somewhere permanent (like a SharedPreference) and update it on pause/restart as needed without using a service? It might be easier if you make a separate question and provide more details of what exactly you're trying to do so we can better help. Also, StackOverflow isn't that suitable for getting opinions on how to do things, so I can't guarantee how much help you'll get. :) – Sam Apr 23 '17 at 08:57
2 Answers
0
How to do it
Here's an up-to-date technique to make it work on all Android versions:
- When the app is running on an Android version prior to 7.1, use this technique.
- When the app is running on Android 7.1 or higher, use this technique.
I know this involves more work than you might like, but it does work, in my experience.
0
Generally, you can not define foreground service without a notification. However, user can hide the notification of your app, so you can ask, but if the service gets started with no notification, it'll be killed by OS as soon as OS felt that it needs to be stopped.
TL; DR
No. For background task execution, the Android WorkManager is the newest and most reliable.

Mahdi-Malv
- 16,677
- 10
- 70
- 117
-
I don't think `WorkManager` can replace background services entirely. Background services does not provide "guaranteed" execution. – stdout Mar 15 '20 at 22:04
-
Well, yeah. In fact, if you don't want to show a notification and start a service (And don't want your service to be killed), you don't have much of a choice. Either Alarm manager or WorkManager. But ofcourse, WM can not replace background service in all cases. – Mahdi-Malv Mar 15 '20 at 22:39