Enhance IntentServices - shiraji/androidannotations GitHub Wiki
Since AndroidAnnotations 3.0
You can enhance an Android IntentService with the @EIntentService
annotation to simply handle actions in @ServiceAction
annotated methods.
As for @EService
, you can then start using most AA annotations, except the ones related to views and extras.
@EIntentService
public class MyIntentService extends IntentService {
public MyIntentService() {
super("MyIntentService");
}
@ServiceAction
void mySimpleAction() {
// ...
}
@ServiceAction
void myAction(String param) {
// ...
}
@Override
protected void onHandleIntent(Intent intent) {
// Do nothing here
}
}
You can start an enhanced IntentService via the inner Builder :
MyIntentService_.intent(getApplication()) //
.myAction("test") //
.start();
If you invoke multiple actions on the builder, only the last action will be executed.
Since AndroidAnnotations 3.3
Note: Since IntentService#onHandleIntent
is abstract, you have to add an empty implementation. For convenience, we provide the AbstractIntentService
class, which implements that method, so you do not have to do in your actual class if you derive it.