excilys/androidannotations — pull request #569 by rom1v (2013-04-22 15:33:32+00:00)
Title: Cancel background tasks

Like [someone asked](https://groups.google.com/forum/#!topic/androidannotations/1_T8_YN2hj0) on the mailing list, I think it would be useful to be able to cancel background tasks, typically in `onStop()`:

~~~java
@Override
protected void onStop() {
super.onStop();
BackgroundExecutor.cancelAll("longtask");
}

@Background(id="longtask")
public void doSomethingLong() {
// ...
}
~~~

I implemented it over my changes adding the [background execution serialization](https://github.com/excilys/androidannotations/pull/564) feature (I changed a bit the implementation).

`@Background` now supports `id` (used for cancellation), `delay` (was already implemented) and `serial` (for serializing tasks) attributes, and any association of them.

As the background execution feature must be reliable, and the interactions between serializing and cancelling must behave correctly, I wrote a set of functional tests.