roboguice.application
Class RoboApplication

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.app.Application
              extended by roboguice.application.RoboApplication
All Implemented Interfaces:
android.content.ComponentCallbacks, InjectorProvider
Direct Known Subclasses:
RoboInjectableApplication

public class RoboApplication
extends android.app.Application
implements InjectorProvider

This class is in charge of starting the Guice configuration. When the getInjector() method is called for the first time, a new Injector is created, and the magic begins !

To add your own custom bindings, you should override this class and override the addApplicationModules(List) method.

You must define this class (or any subclass) as the application in your AndroidManifest.xml file. This can be done by adding android:name="fully qualified name of your application class" to the <application/> tag.

For instance :
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="roboguice.application.RoboApplication"> [...] </application>

Author:
Mike Burton
See Also:
How to get your Application injected as well.

Field Summary
protected  com.google.inject.Provider<android.content.Context> contextProvider
           
protected  ContextScope contextScope
           
protected  EventManager eventManager
           
protected  ExtrasListener extrasListener
           
protected  com.google.inject.Injector guiceInjector
          The Injector of your application.
protected  PreferenceListener preferenceListener
           
protected  ResourceListener resourceListener
           
protected  List<StaticTypeListener> staticTypeListeners
           
protected  com.google.inject.Provider<android.content.Context> throwingContextProvider
           
protected  ViewListener viewListener
           
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, INPUT_METHOD_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Constructor Summary
RoboApplication()
           
 
Method Summary
protected  void addApplicationModules(List<com.google.inject.Module> modules)
          You should override this method to add your own custom bindings.
protected  boolean allowContextObservers()
           
protected  boolean allowPreferenceInjection()
          Returns whether or not InjectPreference will be supported.
protected  com.google.inject.Injector createInjector()
          Creates an Injector configured for this application.
 com.google.inject.Injector getInjector()
          Returns the Injector of your application.
 List<StaticTypeListener> getStaticTypeListeners()
           
protected  void initInstanceMembers()
          Since we don't create the injector when the RoboApplication is instantiated, but rather when getInjector is first called (lazy initialization), the same lazy initialization is applied to this application instance members, which are not used until the injector is first created.
 
Methods inherited from class android.app.Application
onConfigurationChanged, onCreate, onLowMemory, onTerminate
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, sendStickyOrderedBroadcast, setTheme, setWallpaper, setWallpaper, startActivity, startInstrumentation, startIntentSender, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

guiceInjector

protected com.google.inject.Injector guiceInjector
The Injector of your application.


contextScope

protected ContextScope contextScope

throwingContextProvider

protected com.google.inject.Provider<android.content.Context> throwingContextProvider

contextProvider

protected com.google.inject.Provider<android.content.Context> contextProvider

resourceListener

protected ResourceListener resourceListener

viewListener

protected ViewListener viewListener

extrasListener

protected ExtrasListener extrasListener

preferenceListener

protected PreferenceListener preferenceListener

staticTypeListeners

protected List<StaticTypeListener> staticTypeListeners

eventManager

protected EventManager eventManager
Constructor Detail

RoboApplication

public RoboApplication()
Method Detail

getInjector

public com.google.inject.Injector getInjector()
Returns the Injector of your application. If none exists yet, creates one by calling createInjector().

This method is thread-safe.

If you decide to override getInjector(), you will have to handle synchronization.

Specified by:
getInjector in interface InjectorProvider

initInstanceMembers

protected void initInstanceMembers()
Since we don't create the injector when the RoboApplication is instantiated, but rather when getInjector is first called (lazy initialization), the same lazy initialization is applied to this application instance members, which are not used until the injector is first created. The main advantage is that roboguice footprint is close to zero if no RoboActivity is used when running the application.


createInjector

protected com.google.inject.Injector createInjector()
Creates an Injector configured for this application. This Injector will be configured with a RoboModule , plus any Module you might add by overriding addApplicationModules(List).

In most cases, you should NOT override the createInjector() method.


addApplicationModules

protected void addApplicationModules(List<com.google.inject.Module> modules)
You should override this method to add your own custom bindings.
To do so, you must create implementations of the Module interface, and add them to the list of Module given as a parameter. The easiest way to create an Module implementation is to subclass AbstractAndroidModule, which provides proxy methods to the binder methods (enabling more readable configuration)

This method is called by createInjector().

The default implementation is a no-op and does nothing.

Parameters:
modules - The list of modules to which you may add your own custom modules. Please notice that it already contains one module, which is this.

allowPreferenceInjection

protected boolean allowPreferenceInjection()
Returns whether or not InjectPreference will be supported. It is supported by default, but applications that have no RoboPreferenceActivity's may want to turn this off for a slight startup performance gain.


allowContextObservers

protected boolean allowContextObservers()

getStaticTypeListeners

public List<StaticTypeListener> getStaticTypeListeners()


Copyright © 2011. All Rights Reserved.