Skip to content

Instantly share code, notes, and snippets.

@Rapbong
Created July 1, 2019 14:19
Show Gist options
  • Save Rapbong/db28182226c2c3ce616e48ba5ead3cab to your computer and use it in GitHub Desktop.
Save Rapbong/db28182226c2c3ce616e48ba5ead3cab to your computer and use it in GitHub Desktop.
Dagger2 document
public class FrombulationActivity extends Activity {
@Inject Frombulator frombulator;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// DO THIS FIRST. Otherwise frombulator might be null!
((SomeApplicationBaseType) getContext().getApplicationContext())
.getApplicationComponent()
.newActivityComponentBuilder()
.activity(this)
.build()
.inject(this);
// ... now you can write the exciting code
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment