title: Inject activity using dagger
body: <p>I try to create sample application with dagger 2 using mvp &amp; RXAndroid, every thing work correctly but I cannot able to inject Activity the following is my AppComponent<br></p>
  
  <pre><code>@Singleton
  @Component(modules = {AppModule.class})
  public interface AppComponent {
      void inject(App app);
  
      void inject(MainActivity activity);
  
      void inject(ResponseService service);
  
      void inject(MainPresenter presenter);
  }
  </code></pre>
  
  <p>and the following is my Module <br></p>
  
  <pre><code>@Module
  public class AppModule {
  
      private App app;
      public AppModule(App app) {
          this.app = app;
      }
      private static final String API_ENDPOINT = "url here";
  
      @Provides
      @Singleton
      public ApiService apiService() {
          OkHttpClient client = new OkHttpClient();
  
  
          Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ClassTypeAdapterFactory())
                  .registerTypeAdapter(Class.class, new ClassTypeAdapter()).create();
  
  
          Retrofit retrofit = new Retrofit.Builder()
                  .baseUrl(API_ENDPOINT)
                  .addConverterFactory(GsonConverterFactory.create(gson))
                  .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                  .client(client)
                  .build();
  
          return retrofit.create(ApiService.class);
      }
  
      @Provides
      @Singleton
      ResponseService responseService() {
          return new ResponseService(app.getComponent());
      }
  
      @Provides
      @Singleton
      MainPresenter mainPresenter() {
          return new MainPresenter(app.getComponent());
      }
  
      @Provides
      @Singleton
      EventBus eventBus() {
          return EventBus.getDefault();
      }
  }
  </code></pre>
  
  <p>I inject all things correctly and can work with them  except <code>ManiActivity</code>  when try to use it give me null pointer the following how i inject it <br></p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      ((App) getApplicationContext())
              .getComponent()
              .inject(this);
  
      setContentView(R.layout.activity_main);
      ButterKnife.bind(this);
  
      initRecyclerView();
      presenter.setView(this);
  }
  </code></pre>
  
  <p>but when try to use it as Context in My adapter and pass it to Picasso library give me the following exception <code>java.lang.IllegalArgumentException: Context must not be null.
  </code> the following is how i use it </p>
  
  <pre><code>@Inject
  MainActivity activity;
  </code></pre>
  
  <p>and use it in onBindViewHolder as following <br></p>
  
  <pre><code>Picasso.with(activity).load(response).fit().into(holder.ivCover);
  </code></pre>
  
  <p>My adapter code <br></p>
  
  <pre><code>public class ReAdapter extends RecyclerView.Adapter&lt;ReAdapter.RViewHolder&gt; {
      private List&lt;Response&gt; responseList;
  
      @Inject
      MainActivity appContext;
  
  
      public ReAdapter() {
      }
  
      public void setResponseList(List&lt;Response&gt; responseList) {
          this.responseList = responseList;
          notifyDataSetChanged();
      }
  
      @Override
      public RViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.response_item, parent, false);
          return new RViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(RViewHolder holder, int position) {
          final Response response = responseList.get(position);
              Picasso.with(appContext).load(response.getValue().toLowerCase()).fit().into(holder.ivd);
      }
  
      @Override
      public int getItemCount() {
          return responseList != null ? responseList.size() : 0;
      }
  
  
      public class RViewHolder extends RecyclerView.ViewHolder {
          @BindView(R.id.ivd)
          ImageView ivd;
  
          public RViewHolder(View view) {
              super(view);
              ButterKnife.bind(this, itemView);
          }
      }
  }
  </code></pre>
  
  <p>Can anyone help me to solve this issue ?</p>