Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android long running service without notification

I see this example with programs like Advance Task killer, Watch Dog, eBay, battery widgets, ect. There is a background service running that monitors device activity, a broadcastreceiver, but there is an option to disable the notification icon displayed. Currently my application works flawlessly by calling:

Context context = getApplicationContext();
Intent intent = new Intent(context, SomeBackGroundService.class);
context.startService(intent) 

and then in my service I am calling:

startForeground(NOTIFICATION_ID, notification);

Now how is it that these other applications can have a long running broadcastreceiver running without a notification icon? What do I need to do in order to disable/set ect as to hide the icon and add this feature to my application?

Thanks in advance

like image 546
Havoc Avatar asked Feb 18 '26 22:02

Havoc


1 Answers

I'm not expert on this, but I disagree with the accepted answer.

Your startForeground is key to ensuring that your service continues running.

Without that, it might keep running, but it has a much lower priority so it is much more likely to be killed by the system.

like image 126
Tom Avatar answered Feb 21 '26 12:02

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!