For convenience, Roboguice provides "standard injection" support for some of the objects or services commonly used on the Android platform. For example, you do not need to use (Sensormanager) Getsystemservice (Sensor_service) to obtain a Sensormanger instance and use the @inject tag directly
@Inject Sensormanager Sensormanager;
Roboguice automatically injects the required Sensormanger objects for Sensormanager, the standard injection supported by Roboguice is as follows:
@Inject Contentresolver Contentresolver;
@Inject Assetmanager Assetmanager;
@Inject resources;
@Inject Locationmanager Locationmanager;
@Inject WindowManager WindowManager;
@Inject Layoutinflater Layoutinflater;
@Inject Activitymanager Activitymanager;
@Inject PowerManager PowerManager;
@Inject Alarmmanager Alarmmanager;
@Inject Notificationmanager Notificationmanager;
@Inject Keyguardmanager Keyguardmanager;
@Inject Searchmanager Searchmanager;
@Inject Vibrator Vibrator;
@Inject Connectivitymanager Connectivitymanager;
@Inject Wifimanager Wifimanager;
@Inject Inputmethodmanager Inputmethodmanager;
@Inject Sensormanager Sensormanager;
We use Sensormanager as an example to illustrate the usage of standard injection, this example is based on the Android Apidemos sample resolution (m): os->sensors (http:// www.imobilebbs.com/wordpress/?p=1690).
Modify
Private Sensormanager Msensormanager;
For
Private @Inject
Sensormanager Msensormanager;
Remove the onCreate from the
Msensormanager = (Sensormanager) getsystemservice (Sensor_service);
Run the instance, you can see that without using Getsystemservice, Roboguice automatically assigns a value to Msensormanager.
This example downloads: Http://www.imobilebbs.com/download/android/roboguice/StandardInjectionD emo.zip
View a full set of articles: Http://www.bianceng.cn/OS/extra/201301/34950.htm