title: Android fragments - findFragmentByTag always returns null
body: <p>I've had a look around and found a couple of questions with a similar topic, but nothing that helped in my case.
  I'm trying to access an existing active fragment using <strong>getSupportFragmentManager().findFragmentByTag(TAG)</strong>, but it always returns <strong>null</strong>. Replies on similar questions suggested that it takes a while for the commit to be executed, so calling findFragmentByTag would return null if called too early. I've tried two things:</p>
  
  <ul>
  <li>add <strong>getSupportFragmentManager().executePendingTransactions()</strong><br>
  immediately after the commit, but still get <strong>null</strong>.</li>
  <li>added a button... pressing this after the activity has been created,
  the fragment registered and the view displayed should leave    the
  system enough time to commit. But i still get <strong>null</strong>.</li>
  </ul>
  
  <p>Here's my activity:</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
  private static final String F_SETTINGS = "f_settings";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_main);
  
      Button btn = (Button) findViewById(R.id.btn);
      btn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              debug();
          }
      });
  
      if (savedInstanceState == null) {
          FSettings newFragment = new FSettings();
          FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
          ft.replace(R.id.container, newFragment);
          ft.addToBackStack(F_SETTINGS);
          ft.commit();
          // getSupportFragmentManager().executePendingTransactions();
          //// Activating this did not make any difference...
      }
  
      debug();
  }
  
  private void debug() {
      String txt = "null";
      Fragment frag = getSupportFragmentManager().findFragmentByTag(F_SETTINGS);
      if (frag != null) {
          txt = frag.toString();
      }
      Log.i("Testing", txt);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>What am I doing wrong here?
  Cheers,
  Max</p>