What dependency injection framework are you using? It looks like it might be dagger, in which case you can just use a constructor with an @Inject
annotation and have the dependencies passed in through it like this (where Foo is your class and Bar is the dependency):
private final Bar mBar;
@Inject
public Foo(Bar bar) {
mBar = bar;
}
In your module you'll need something like:
@Provides
public Foo providesFoo(Foo foo) {
return foo;
}
If you aren't using dagger (and even if you are), I'd recommend making a static method in your application class to get the instance of your application to avoid casting it, and allow it to be accessible from anywhere within your app (although I'd personally only call it in Activities/Fragments/Services/etc.). I use something like this:
private static App sInstance;
public static App getInstance() {
return sInstance;
}
@Overrride
public void onCreate() {
super.onCreate();
sInstance = this;
}