| Start |
|---|
| Simple example RoboGuice is a framework that brings the simplicity and ease of Dependency Injection to Android, using Google's own Guice library. |
| Installation for Gradle Projects Add the following pom to the dependencies section of your gradle build file : |
| @ContentView annotation The @ContentView annotation can be used to further alleviate development of activities and replace the setContentView statement : |
| @InjectResource annotation You can inject any type of resource, Strings, Animations, Drawables, etc. To inject your first resource into an activity, you'll need to:
Example |
| @InjectView annotation You can inject any view using the @InjectView annotation: You'll need to:
Example |
| Introduction to RoboGuice
RoboGuice 3 slims down your application code. Less code means fewer opportunities for bugs. It also makes your code easier to follow -- no longer is your code littered with the mechanics of the Android platform, but now it can focus on the actual logic unique to your application. To give you an idea, take a look at this simple example of a typical Android This example is 19 lines of code. If you're trying to read through Compare this to the same app, written using RoboGuice's goal is to make your code be about your app, rather than be about all the initialization and lifecycle code you typically have to maintain in Android. Annotations: @ContentView annotation: The @ContentView annotation can be used to further alleviate development of activities and replace the setContentView statement : @InjectResource annotation: First you need an Activity that inherits from RoboActivity. Then, assuming that you have an animation my_animation.xml in your res/anim folder, you can now reference it with an annotation: @Inject annotation: You make sure your activity extends from RoboActivity and annotate your System service member with @Inject. Roboguice will do the rest. In addition to Views, Resources, Services, and other android-specific things, RoboGuice can inject Plain Old Java Objects. By default Roboguice will call a no argument constructor on your POJO |
Read Article
https://develop.horje.com/learn/1434/reference