title: Activity And Fragment Interaction
body: <p>I have an <code>Activity</code> with multiple <code>Fragment</code>s. I want to show a <code>DialogFragment</code> or open another <code>Fragment</code> from one of the <code>Fragment</code>s. I know that an <code>Activity</code> should be the one tasked with opening <code>Fragment</code>s so instead I have tried a couple things.</p>
  
  <p><strong>FIRST</strong><br>
  I tried to use <code>getActivity()</code> and cast it so I can call a method in the <code>Activity</code> to show a <code>Fragment</code> however this creates a dependency in the <code>Fragment</code> with the <code>Activity</code> and I would like to avoid adding a dependency if possible.<br><br>
  <strong>SECOND</strong><br>
  Next I tried a listener to notify the <code>Activity</code> that it should show a <code>Fragment</code>. So I created a class in the <code>Activity</code> to implement the listener interface. But I had problems because I had to use <code>New MyActivity().new Listener();</code> and it would throw an <code>Exception</code> when I tried to use <code>getSupportFragmentManager()</code> since this instance of the <code>Activity</code> is not initialized.<br><br>
  <strong>THIRD</strong><br>
  I then tried to have the <code>Activity</code> implement the listener directly which works because then I am only creating a dependency with the listener and not the Activity. However now I am getting to the point where my <code>Activity</code> will be implementing 2 - 4 different interfaces which is making me hesitant because it will severely reduce cohesion.<br><br></p>
  
  <p>So any way I have tried I seem to be running into a brick wall and creating dependancies I'm not sure I need to be creating. Am I screwed and have to go with one of these options? If so which option would be best? Any help or suggestions are are greatly appreciated.</p>