博不如精

完美靠的是质量而非数量。世上的好东西时常小而难求,过多必无誉。只靠广博则难免成为平庸之辈,有所谓通才总想在学业上门门皆精,结果却常常是门门皆瘟。学业专攻必结硕果;若从事重要的事务,则必得美名。...

AndroidAnnotations——Enhance services优化服务

Enhance services 优化services

Since AndroidAnnotations 2.4


You can enhance an Android Service with the @EService annotation:
你可以使用 @EService 优化Android Service:

@EService
public class MyService extends Service {

}

You can then start using most AA annotations, except the ones related to views and extras:
然后,除了Views和extras相关的注解,你可以使用大多数AA的其他注解:

@EService
public class MyService extends IntentService {

  @SystemService
  NotificationManager notificationManager;

  @Bean
  MyEnhancedDatastore datastore;

  @RestService
  MyRestClient myRestClient;

  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 activity via the inner Builder :
你可以通过内部构造器启动一个优化的activity:

MyService.intent(getApplication()).start();

Since AndroidAnnotations 3.0

When the 3.0 will be released you'll be able to stop a service with the Builder. This page will be updated at this moment.

本文档的简单示例下载

阅读更多
文章标签: AndroidAnnotation
上一篇AndroidAnnotations——Enhancing the Application class优化Application类
下一篇AndroidAnnotations——Enhance broadcastreceivers优化广播接收器
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭