Roboguice – use it, it’s really easy.

Roboguice is an awesome thing. If, like me, you put off looking into it for fear it might be time consuming then don’t fear: it is really, really easy.  Using it simply you can forget about loads of boilerplate code like findViewById, Context.getSystemService and so on.

The project’s getting started page tells you all you need to know, although it is perhaps a little bit vague in the application and module areas.  From this page you should grab the two jars and add it to your project.

After this you’ll need to create a class that extends RoboApplication.  If you want to use RoboGuice in its simplest form you can ignore the stuff about modules for now.  The chances are you’ll definitely want to use them soon but to keep things simple your Application class can look as simple as this:

public class MainApplication extends RoboApplication {
    // That's it, you don't even need anything in here yet!

The next step is to open up your AndroidManifest.xml file and put in a reference to this new Application class.  I find the easiest way to do this (in eclipse) is to right click on the class name and click ‘copy qualified name’.  This will give you the full name like ‘com.mbcdev.nextluas.MainApplication’.  You will already have an ‘application’ element in the manifest so simply add the ‘android:name’ attribute with the qualified class name of the Application class.

<application android:name="com.mbcdev.nextluas.MainApplication" ... />

That’s it for the setup.  The next steps would be to look at the provided example and provided injections to give you a flavour of what you can do.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s