使用一个后台任务和另一个后台任务的服务

时间:2016-04-15 00:49:35

标签: android service handler intentservice looper

我需要让IntentService只处理一个待处理任务(最后一个)。 例如,如果服务已在运行并且它接收到另一个任务,那么该任务将保留在队列中并在当前任务结束后运行。问题是如果收到第三个任务,那么我希望删除所有待处理的任务,只留下最后一个留在队列中。

任何想法我该怎么做?到目前为止,我试图扩展服务并创建自己的自定义服务而不是IntentService。我不确定这是否正确。

    @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;
}

0 个答案:

没有答案
相关问题