Vishnudev K Vishnudev K - 1 month ago 9
Android Question

How to prevent android service getting killed (Service with notification)

I am working on an application which need to show notification constantly.

I've a service to show the notification every seconds.

When the resources goes low android is killing my service.

I've given the return START_STICKY from onStartCommand().

So after some time the service is getting restarted.

But in the mean time the notification look stoped.

I red somewhere that it is possible for a service showing notification prevented from getting stoped by android. I dint get any example for it.

Answer

As written above you need to use startForeground(int,Notification) method to aware user about your service. It also get more privilage for it.

You can read more about it here (example inside).