title: Get the last fragment in back stack
body: <p>I have seen this post but the solutions posted here are not working for me: <a href="https://stackoverflow.com/questions/9702216/get-the-latest-fragment-in-backstack">get the latest fragment in backstack</a></p>
  
  <p>When I replace a fragment for another I use:</p>
  
  <pre><code>FragmentManager manager = getSupportFragmentManager();
      FragmentTransaction ft = manager.beginTransaction();
  
      ft.replace(android.R.id.tabcontent, fragment, tag);
      ft.addToBackStack(null);
  
      ft.commit();
  </code></pre>
  
  <p>So, please notice that I'm using tags to detect any fragment.</p>
  
  <p>My problem in particular is the following:</p>
  
  <p>Suppose I have fragment_A, fragment_B and fragment_C. I can get to fragment_C from fragment_A or fragment_B and depending of the parent of call I have to do something particular. So, again I need to recover the last FRAGMENT in the back stack. </p>
  
  <p>When I try to do:</p>
  
  <pre><code>FragmentManager fm = getSupportFragmentManager();
  
          for(int entry = 0; entry &lt; fm.getBackStackEntryCount(); entry++){
              String ide = fm.getBackStackEntryAt(entry).getName();
             Log.i("TAG", "Found fragment: " + ide);
          }
  </code></pre>
  
  <p>I get nulls. If I use getId() instead, I get numbers so I tried doing:</p>
  
  <pre><code>int id = fm.getBackStackEntryAt(entry).getId();
  Fragment fragment = fm.findFragmentById(id);
  Log.i("TAG", "Found fragment: " + fragment.getTag());
  </code></pre>
  
  <p>But I get nulls.. I dont know what else to do, so any help will be appreciated. </p>
  
  <p>Edit: I call this methods in onBackPressed() { ...}</p>