Skip to content

Enhance broadcastreceivers

PerfectCarl edited this page May 28, 2014 · 20 revisions

Since AndroidAnnotations 2.4

You can enhance an Android BroadcastReceiver with the @EReceiver annotation:

@EReceiver
public class MyReceiver extends BroadcastReceiver {

}

You can then start using most AA annotations, except the ones related to views and extras:

@EReceiver
public class MyReceiver extends BroadcastReceiver {

  @SystemService
  NotificationManager notificationManager;

  @Bean
  SomeObject someObject;
  
}

The @Receiver annotation

You can use the enhanced receiver by code using the @Receiver annotation, to register it programmatically for example(instead of using the manifest).

  @Receiver
  ModuleDownloadedReceiver receiver ;

  private void registerReceiver() {
    IntentFilter filter = new IntentFilter();
    filter.addAction("android.intent.action.DOWNLOAD_COMPLETE");
    context.registerReceiver(receiver, filter);
  }

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally