I need to perform long running task. In that task I would copy something from one place to another.
I've tried to use IntentService for that, but the problem is that it can be killed and I will lose all work in that case. I know that I could tell the system that I need to restart it ASAP, and the service could know about it, but I need to start work exactly from where I was left.
It's not so difficult to do that in "stupid way". Say I use some persistent storage to store some "pointer" to the point where I left and somehow start working from that point.
But the thing is I would need to do a lot of work to do that. Like recompute progress to display in notification. Also it would require serious rewrite of the code which now looks like that.
public class Exporter implements ElementExporter {
@Override
public void exportElements(ReadableElementStorage from, WritableElementStorage to) throws IOException {
while (from.hasNextElement()) {
Element element = from.loadElement();
to.saveElement(element);
}
}
}
I think that there should be some framework to do long running task, which could be cancelled and restarted after some crash. Or maybe you would suggest a better design?