Enhance services - WonderCsabo/androidannotations GitHub Wiki
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();