Reputation: 143
How to prevent a Service
which should run without showing a notification from being killed even if the app is killed?
I'm trying to run a Service
which tracks GPS location after every 10 minutes and I want my Service
to run continuously even if the app is killed. I've already tried startForeground()
but it also gives me a notification. How can I get a solution without notification?
Upvotes: 3
Views: 1808
Reputation: 143
Try to use START_STICKY
or apply wake lock which calls the service immediately as soon as it stops.
Upvotes: 0
Reputation: 1127
You can return START_REDELIVER_INTENT
from your Service
onStartCommand
. So when your service is killed, the service will be restarted and last delivered intent will be sent.
Also you can return START_STICKY
to auto-restart the service killed by android.
So if even user swipes close the app from open apps screen, your service will restart.
Upvotes: 1