2015-09-01 37 views
-1

在Android中,它们使得它看起来像一个IntentService,是在上传背景中的pdf列表时要走的路。IntentService:如何添加和从工作队列中删除意图?

如何实际访问工作队列以便从工作队列中删除特定项目?如果上传该项目由于某种原因失败,我也想重新添加一个项目到队列中。

任何想法?

回答

0

不能从队列中删除的东西,但你可以标志事情可略过像这样的东西:

private static Collection<Object> cancelledThingIds; 

public static void cancelThing(Object thingId){ 
    cancelledThingIds.add(thingId); 
} 

@Override 
protected void onHandleIntent(Intent intent) { 
    if (intent != null) { 
     final Object thing = intent.getExtra(EXTRA_THING); 

     if(cancelledThingIds.contains(thing.getId())) 
      cancelledThingIds.remove(thing); 
     else{ 
      processThing(thing); 
     } 
    } 
} 

项目的重试更加简单不过 - 只需创建一个新的新意图您的意愿服务并再次启动。你可以在意图中包含额外的“尝试编号”,如果你尝试了太多次,你可以做其他事情。