Android Roboguice Usage Guide (Standard) injection

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.