Installation
Download RoboGuice and guice-2.0-no_aop.jar (not guice-3.0).
Create a new Android Project (or use an existing one), targeting at least platform 1.5, API level 3 and SDK Version 3.
Add the two jars to the build path of your Android project
- Eclipse : Project > Properties > Java Build Path > Libraries > Add External JARs
- IntelliJ: File -> Project Structure -> Modules ->Your App -> Dependencies -> Add -> Single Entry Module...
Create a new class that extends RoboApplication
(let's call it MyApplication
).
Update the android:name attribute of application in the AndroidManifest.xml to set your newly created application. For instance, in our example it would be :
<application android:name="com.mycompany.myproject.MyApplication" ... >
Create a configuration Module class that extends AbstractAndroidModule
(let's call it MyModule
). Implement the configure()
method to add your own bindings. See the Google Guice Wiki to learn more about configuring Modules.
Override RoboApplication.addApplicationModules(List<Module>)
method in your application class. Add a new instance of your custom Module to the list. For instance :
public class MyApplication extends RoboApplication { protected void addApplicationModules(List modules) { modules.add(new MyModule()); } }
Make your activities extend from RoboActivity
instead of Activity
.
You are ready to start using RoboGuice! To see examples of what you can do, check out the example in the samples directory.
- For Projects Using Gradle
- For Projects Using Maven
- Manual Installation for Older Projects
- Inheriting from RoboGuice Classes
- Upgrade Instructions from RoboGuice 2
- Your First View Injection
- Your First Resource Injection
- Your First System Service Injection
- Your First POJO Injection
- Singletons and ContextSingletons (wiki/Understanding Scopes)
- Your First Custom Binding
- Your First Injected Fragment
- Your First Injected Service and BroadcastReceiver
- Your First Testcase
- Your First Injection into a Custom View class
- Your First Injected ContentProvider
- Using Events in your RoboGuice application
- Logging via Ln
- RoboGuice Standard Injections
- How Injection Works
- When Injection Just Works, and when you have to call injectMembers()
- The Difference between Global and Context-scoped Injection
- Analyzing a Guice Stack Trace
- What's the difference between Nullable and Optional?
- RoboBlender wiki
- Use ProGuard with RoboGuice
- Define advanced custom bindings
- Remove or replace RoboGuice's default bindings
- Use your own BaseActivity with RoboGuice
- Inject into an object that you don't instantiate
- Dealing with Circular Dependencies
- Work with Library Projects
- Deal with ComputationException due to StackOverflowError
- Taming Fragmentation using RoboGuice