I want to get RefWatcher object available throughout my activities and fragments so in my main application dagger module i did
@Provides
@AppScope
static RefWatcher provideRefWatcher(Application application) {
return ((AppName) application).refWatcher;
}
and in my application class I declared
public class AppName extends DaggerApplication {
public RefWatcher refWatcher;
...
}
However when i inject into activity and use as
public class MainActivity extends DaggerAppCompatActivity {
@Inject
RefWatcher refWatcher;
@Override
public void onDestroy() {
super.onDestroy();
refWatcher.watch(this);
}
Iam getting error
Caused by: java.lang.NullPointerException: Cannot return null from a non-@Nullable @Provides method
What is the correct way to inject this leakcanary refwatcher?