I need to make the IntentService to process only one pending task (the last one). For example if the service is already running and it receive another task then that task is kept in the queue and run after the current one ended. The problem is that if a third task is received then I want that all pending tasks to be removed and only the last one to be left in the queue.
Any ideas how can I do this? So far I was trying to extend Service and create my own custom Service instead of IntentService. I am not sure if this is the right way.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mServiceHandler.removeCallbacksAndMessages(null); // add this
onStart(intent, startId);
return mRedelivery ? START_REDELIVER_INTENT : START_NOT_STICKY;
}