SystemServices

Csaba Kozák edited this page Mar 16, 2016 · 9 revisions

Since AndroidAnnotations 1.0

Standard Android System Service injection

Retrieving Android System Services requires remembering the name of the constant, and casting the retrieved object.

notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

@SystemService

The @SystemService annotation indicates that an activity field should be injected with the corresponding Android System service.

It is the same as calling the Context.getSystemService() method.

Usage example:

@EActivity
public class MyActivity extends Activity {

  @SystemService
  NotificationManager notificationManager;

}

Method based injection

Since AndroidAnnotations 4.0.0

@EActivity
public class MyActivity extends Activity {

  @SystemService
  void setNotificationManager(NotificationManager notificationManager){
    // do something with notificationManager
  }
  
  void setMultipleServices(@SystemService NotificationManager notificationManager, @SystemService AudioManager audioManager){
    // do something with notificationManager and audioManager
  }

}

21/10/2018 The 4.5.2 release is out !

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.