forked from androidannotations/androidannotations
-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance services
WonderCsabo edited this page Nov 7, 2014
·
19 revisions
Since AndroidAnnotations 2.4
You can enhance an Android Service with the @EService
annotation:
@EService
public class MyService extends Service {
}
You can then start using most AA annotations, except the ones related to views and extras:
@EService
public class MyService extends IntentService {
@SystemService
NotificationManager notificationManager;
@Bean
MyEnhancedDatastore datastore;
@RestService
MyRestClient myRestClient;
@OrmLiteDao(helper = DatabaseHelper.class, model = User.class)
UserDao userDao;
public MyService() {
super(MyService.class.getSimpleName());
}
@Override
protected void onHandleIntent(Intent intent) {
// Do some stuff...
showToast();
}
@UiThread
void showToast() {
Toast.makeText(getApplicationContext(), "Hello World!", Toast.LENGTH_LONG).show();
}
}
You can start an enhances service via the inner Builder :
MyService_.intent(getApplication()).start();
Since AndroidAnnotations 3.0
The inner builder provide a stop method to stop this enhanced service:
MyService_.intent(getApplication()).stop();
AndroidAnnotations was created by Pierre-Yves Ricau and is sponsored by eBusinessInformations.
09/11/2014 The 3.2 release is out !
- Get started!
- Download
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow