title: How can I tell if 2 fragments have an instance from the same class
body: <p>Let's say that I have a fragment inside a container that I should replace with an other fragment.</p>
  
  <p>The code is quite simple:</p>
  
  <pre><code>getSupportFragmentManager().beginTransaction().
  replace(R.id.content_frame,fragmentToAdd).addToBackStack(null).commit();
  </code></pre>
  
  <p>The problem is now that I want to make sure that fragmentToAdd is not similar to the fragment I will replace.</p>
  
  <p>If this is the case, the app should do nothing.</p>
  
  <p>So, I can get the original Fragment:</p>
  
  <pre><code>Fragment originalFragment=(Fragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
  </code></pre>
  
  <p>and the final code would be something like:</p>
  
  <pre><code>if (haveDifferentInstance(originalFragment,fragmentToAdd)){
      getSupportFragmentManager().beginTransaction().
      replace(R.id.content_frame,fragmentToAdd).addToBackStack(null).commit();}
  else
      // Do nothing
  </code></pre>
  
  <p>So, what could be the code for haveDifferentInstance(Fragment fragmentA, Fragment fragmentB)?</p>
  
  <p>Thank for any help.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I know that I can do somethinh like:</p>
  
  <pre><code>if (fragmentToAdd instanceof FragmentA)
  </code></pre>
  
  <p>But has I have FragmentA, FragmentB, .... Fragment F, I don't want to use a 'if' per type of Fragment.</p>