Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Enhance IntentServices

Kay-Uwe Janssen edited this page Mar 30, 2017 · 8 revisions

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.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally