Roboguice Custom Module Application Context
How do I get the application context in my custom module? Here is the code for my module: public class MyModule extends AbstractModule { @Override @SuppressWarnings('unchec
Solution 1:
Just inject it in constructor
publicfinalclassMyModuleextendsAbstractModule
{
privatefinal Context context;
@InjectpublicMyModule(final Context context)
{
super();
this.context = context;
}
@Override@SuppressWarnings("unchecked")protectedvoidconfigure() {
// Package Infotry {
finalPackageInfoinfo= context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_META_DATA);
bind(PackageInfo.class).toInstance(info);
} catch (PackageManager.NameNotFoundException e) {
thrownewRuntimeException(e);
}
}
}
Post a Comment for "Roboguice Custom Module Application Context"