title: Call Method in Fragment from Unrelated Class
body: <p>Tricky question here, but I will try and be clear.</p>
  
  <p>Class A: <code>extends FragmentActivity</code> and has the <code>FragmentManager</code></p>
  
  <p>Class B: <code>extends Fragment</code> and has the fragment's UI</p>
  
  <p>Class C: Unrelated Class</p>
  
  <pre><code>    public class A extends FragmentActivity{
          Fragment fragment = new FragmentActivity();
      }
  
      public class B extends Fragment{
          public void methodToBeCalled(){
               //do something
  }
      }
  
      public class C{
          //call B's methodToBeCalled() from here
          //note it is not static
      }
  </code></pre>
  
  <p>What I want to do is call a method which is located in Class B from Class C.  Any ideas how I could go about doing this?</p>
  
  <p>A solution would be a way to run this code from Class C:</p>
  
  <pre><code>B fragment = (B) getFragmentManager().findFragmentById(R.id.b);
  </code></pre>
  
  <p>This does not work (it compiles, but the if statement is always false):</p>
  
  <pre><code>    if (A.getCurrentFragment() instanceof B) {
          B fragment = (B) A.getCurrentFragment();
          fragment.methodToBeCalled();
      }
  </code></pre>