I have created a service to fetch current location of the device in periodic intervals. I want the service to run in the background even if the app is cleared from recently
If you ONLY want to restart service after it kill from Recent Task, simple use
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_STICKY;
}
If you use START_STICKY, when you kill app from recent task, your service will be killed (onTaskRemoved fired, onDestroy NOT fired) THEN it will auto start again (onCreate fired, onStartComand fired)