title: How to pass data to child fragment while using dagger 2
body: <p>I want to pass some data from fragment parent to dialog fragment child. The trouble is I cannot pass the data through bundle since dagger instantiates fragment dialog, so the bundle is always null. I am using dagger 2.12..</p>
  
  <p>I'm new to Dagger 2, so this might be something trivial. I am still trying to wrap my head around it.</p>
  
  <p>I followed <a href="https://proandroiddev.com/how-to-android-dagger-2-10-2-11-butterknife-mvp-part-1-eb0f6b970fd" rel="nofollow noreferrer">this</a> tutorial, and adopted it to suit my application. To keep it simple here is my MainFragment:</p>
  
  <pre><code>public class MainFragment extends BaseFragment {
  
      @Nullable
      @Override
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
          this.setHasOptionsMenu(true);
          return inflater.inflate(R.layout.my_fragment, container, false);
      }
  
      @Override
      public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
          super.onCreateOptionsMenu(menu, inflater);
          inflater.inflate(R.menu.my_menu, menu);
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch(item.getItemId()) {
              case R.id.action_delete:
                  Bundle args = new Bundle();
                  args.putString("BUNDLE_TITLE_KEY", getResources().getString(R.string.dialog_delete_name));
                  args.putString("BUNDLE_MESSAGE_KEY", getResources().getString(R.string.delete_message));
                  addDialogFragment(new ConformationFragmentDialog(), args);
                  break;
              default:
                  return super.onOptionsItemSelected(item);
          }
          return true;
      }
  }
  </code></pre>
  
  <p>Here is BaseFragment (extended by MainFragment):</p>
  
  <pre><code>public class BaseFragment extends Fragment implements HasFragmentInjector {
  
      @Inject
      @Named(BaseFragmentModule.CHILD_FRAGMENT_MANAGER)
      FragmentManager childFragmentManager;
  
      @Inject
      DispatchingAndroidInjector&lt;Fragment&gt; childFragmentInjector;
  
      @Override
      public void onAttach(Context context) {
          AndroidInjection.inject(this);
          super.onAttach(context);
      }
  
      @Override
      public AndroidInjector&lt;Fragment&gt; fragmentInjector() {
          return childFragmentInjector;
      }
  
      protected final void addDialogFragment(DialogFragment dialogFragment, Bundle bundle) {
          dialogFragment.setArguments(bundle);
          childFragmentManager.beginTransaction().add(dialogFragment, "Hello").commit();
      }
  }
  </code></pre>
  
  <p>And here is ConformationFragmentDialog:</p>
  
  <pre><code>public class ConformationFragmentDialog extends DialogFragment {
  
      @Override
      public void onAttach(Context context) {
          AndroidInjection.inject(this);
          super.onAttach(context);
      }
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
          dialogBuilder.setNegativeButton(R.string.common_odustani, new DialogInterface.OnClickListener() {
              //TODO: set title and message dynamically, bundle is null
          }).setTitle("TITLE").setMessage("MESSAGE");
          return dialogBuilder.create();
      }
  }
  </code></pre>
  
  <p>Here are BaseFragmentModule and MainFragmentModule:</p>
  
  <pre><code>@Module
  public abstract class BaseFragmentModule {
      public static final String FRAGMENT = "BaseFragmentModule.fragment";
      public static final String CHILD_FRAGMENT_MANAGER = "BaseFragmentModule.ChildFragmentManager";
  
  
      @Provides
      @Named(CHILD_FRAGMENT_MANAGER)
      static FragmentManager childFragmentManager(@Named(FRAGMENT) Fragment fragment) {
          return fragment.getChildFragmentManager();
      }
  }
  
  
  @Module(includes = BaseFragmentModule.class, subcomponents = ConformationFragmentDialogSubcomponent.class)
  public abstract class MainFragmentModule {
  
      @Binds
      @IntoMap
      @FragmentKey(ConformationFragmentDialog.class)
      abstract AndroidInjector.Factory&lt;? extends Fragment&gt; conformationFragmentDialog(ConformationFragmentDialogSubcomponent.Builder builder);
  
  
      @Binds
      @Named(BaseFragmentModule.FRAGMENT)
      abstract Fragment fragment(UvjetListFragment uvjetListFragment);
  
  }
  </code></pre>
  
  <p>At this moment, ConformationFragmentDialogModule is empty and Subcomponents are basic subcomponents.</p>
  
  <p>I want ConformationFragmentDialog to be reusable in different fragments. How can I set different title and message for every fragment from which I am calling ConformationFragmentDialog, while still doing things in dagger appropriate manner?</p>