Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. @Module
  2. public class AppModule {
  3.  
  4. private Context appContext;
  5.  
  6. public AppModule(Context appContext){
  7. this.appContext = appContext;
  8. }
  9.  
  10. @Provides
  11. @Singleton
  12. Context provideContext(){
  13. return appContext;
  14. }
  15. }
  16.  
  17.  
  18. @Component(modules={ AppComponent.class })
  19. @Singleton
  20. public class AppComponent {
  21.  
  22. void inject(MainActivity act);
  23. }
  24.  
  25. public class App extends Application {
  26. public static AppComponent appCompanent;
  27. onCreate() {
  28. appComponent = DaggerAppComponent.builder()
  29. .appModule(AppModule(this))
  30. .build();
  31. }
  32. }
  33.  
  34. public class MainActivity extends Activity {
  35.  
  36. @Inject
  37. Context appContext;
  38.  
  39. @Override
  40. void onCreate() {
  41. App.appCompanent.inject(this);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement