Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@hanspeide hanspeide commented Jan 13, 2016

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

This comment has been minimized.

Copy link
Owner Author

@hanspeide hanspeide commented Jan 13, 2016

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