Skip to content

Instantly share code, notes, and snippets.

@hanspeide
Created January 13, 2016 13:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanspeide/75f7f16551f5e273ff89 to your computer and use it in GitHub Desktop.
Save hanspeide/75f7f16551f5e273ff89 to your computer and use it in GitHub Desktop.
public abstract class BaseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (requestInjection()){
inject();
}
}
private void inject() {
ObjectGraph appGraph = Injector.obtain(getApplication());
appGraph.inject(this);
}
abstract boolean requestInjection();
}
public class SomeActivity extends BaseActivity {
@Inject ApiService apiService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.some_layout);
}
@Override
boolean requestInjection() {
return true;
}
}
@hanspeide
Copy link
Author

Compile error:
Caused by: java.lang.IllegalArgumentException: No inject registered for members/com.example.SomeActivity. You must explicitly add it to the 'injects' option in one of your modules.

@hanspeide
Copy link
Author

Solution: Add SomeActivity.class to the module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment