title: Fragment.isVisible() returns false even when Fragment added and visible
body: <p>I am perplexed by how Fragment.isVisible() is supposed to work. Even though I have a fragment added in <code>Activity.create()</code>, <code>Fragment.isVisible()</code> returns false even when <code>FragmentManager.commitNow()</code> is used. </p>
  
  <p><code>Fragment.isVisible()</code> returns false even in <code>onResume()</code>. However, when a UI button gets clicked the returned value is correct.</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
  public final static String TAG = "HideFragmentOnChange";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      ((Button)findViewById(R.id.my_button)).setOnClickListener(this);
  
      if(savedInstanceState == null){
          Fragment fragmentA = new FragmentA();
  
          Log.d(TAG, "onCreate: Before FragmentTransaction FragA: " + (fragmentA.isVisible() ? "visible" : "not visible"));
  
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.fragment_container, fragmentA, "fragA")
                  .commitNow();
  
          Log.d(TAG, "onCreate: After FragmentTransaction FragA: " + (fragmentA.isVisible() ? "visible" : "not visible"));
  
      }
  
      this.runOnUiThread(new Runnable(){
          @Override
          public void run() {
              Fragment fragA = getSupportFragmentManager().findFragmentByTag("fragA");
              Log.d(TAG, "runOnUiThread after onCreate(): FragA: " + (fragA.isVisible() ? "visible" : "not visible"));
          }
      });
  }
  
  @Override
  protected void onResume() {
      super.onResume();
  
      Fragment fragA = getSupportFragmentManager().findFragmentByTag("fragA");
      Log.d(TAG, "onResume: FragA: " + (fragA.isVisible() ? "visible" : "not visible"));
  
      this.runOnUiThread(new Runnable(){
          @Override
          public void run() {
              Fragment fragA = getSupportFragmentManager().findFragmentByTag("fragA");
              Log.d(TAG, "runOnUiThread after onResume(): FragA: " + (fragA.isVisible() ? "visible" : "not visible"));
          }
      });
  }
  
  @Override
  public void onClick(View v) {
      Fragment fragmentA = getSupportFragmentManager().findFragmentByTag("fragA");
      Log.d(TAG, "onClick(): FragA: " + (fragmentA.isVisible() ? "visible" : "not visible"));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I initially thought that perhaps it is because the main thread has not had the chance to run yet and the <code>FragmentTransaction</code> does not fully and properly commit until a later point. However, calling <code>runOnUiThread</code> does not change the return value of <code>isVisible()</code>.</p>
  
  <p>I am attaching the log for reference.</p>
  
  <pre><code>03-15 17:22:34.978 14094-14094/ D/HideFragmentOnChange: onCreate: Before FragmentTransaction FragA: not visible
  03-15 17:22:34.990 14094-14094/ D/HideFragmentOnChange: onCreate: After FragmentTransaction FragA: not visible
  03-15 17:22:34.991 14094-14094/ D/HideFragmentOnChange: runOnUiThread after onCreate(): FragA: not visible
  03-15 17:22:34.996 14094-14094/ D/HideFragmentOnChange: onResume: FragA: not visible
  03-15 17:22:34.996 14094-14094/ D/HideFragmentOnChange: runOnUiThread after onResume(): FragA: not visible
  03-15 17:22:56.683 14094-14094/ D/HideFragmentOnChange: onClick(): FragA: visible
  </code></pre>
  
  <p>Why does <code>Fragment.isVisible()</code> seem to return the correct value with such a big delay?</p>
  
  <p>I am using support library 25.2 and support library Fragments although native fragments produced the same behavior.</p>