-1

in Android they make it seem like an IntentService is the way to go when uploading a list of pdfs in the background.

How does one actually access the worker queue in order to delete a particular item from the worker queue? I also would like to re-add an item to the queue if uploading that item fails for some reason.

Any ideas?

user798719
  • 9,619
  • 25
  • 84
  • 123

1 Answers1

1

You can't delete something from the queue, but you could flag things as skippable with something like this:

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

The retrying of items is much more straightforward though - simply create a new fresh intent for your intentservice and start it again. You could include something like a "attempt number" extra within the intent so you can do something else if you've tried too many times.

JoeyJubb
  • 2,341
  • 1
  • 12
  • 19