So I want my android app services to run even if I remove it from the list of recent app.some thing like wattsapp and facebook how can i do that?
Asked
Active
Viewed 254 times
-2
-
1Use sticky service for it – Anand Savjani Sep 23 '15 at 09:48
-
1possible duplicate of [Background Service getting killed in android](http://stackoverflow.com/questions/12219249/background-service-getting-killed-in-android) – glethien Sep 23 '15 at 09:57
2 Answers
2
You've to make your service a STICKY Service.
To do that, within your onStartCommand method, return START_STICKY. This will ensure that even if a Service gets stopped, it'll be restarted by the OS.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Your code here.
return Service.START_STICKY;
}
Then from your activity, you just need to start the service once..
startService(new Intent(this, YourService.class));

Rachit
- 3,173
- 3
- 28
- 45
0
Well Alarm manager helped but I'm still stuck in Async Task though I'have my alarm set at every 20 second sometimes it take more than 20 sec and some times less so I think it's because of Async task where I'm fetching data from database.
Anyways Thanks.

Sarika Rajput
- 63
- 2
- 11