title: How to call Activity method from outside library in Android
body: <p>In my main activity I am having a method that I need to call from a secondary java class. I used the constructor of the secondary java class to receive reference to the main Activity. I then tried to use this reference to invoke that method from the body of the secondary java class. But java doesn't recognize that method through the passed reference?</p>
  
  <p>My <strong>main Activity</strong> is as below:</p>
  
  <pre><code>public class MainActivity extends Activity{
  
      public void onCreate(){
  
          TestClass mTestClass = new TestClass(this);
      }
  
     public testMethod(){      
         // do some work here
     }
  }
  </code></pre>
  
  <p>now, in my <strong>TestClass.java</strong> I receive reference to the MainActivity:</p>
  
  <pre><code>public class TestClass{
  
      public TestClass(Activity mActivity){
          //Android/Java doesn't recoginze testMethod here???? 
          mActivity.testMethod();      
      }
  }
  </code></pre>
  
  <p>I've been trying to solve this issue for a few days with no success. I urgently need your help and would appreciate any suggestion!</p>
  
  <p>P.S. The TestClass will act as a library that everyone can call it from their android application. In other words, I provide the TestClass as the library. The user then implements the content of a method that will be executed whenver certain conditions are met. Thus, I need to call that specific method (which will be defined by the user in their own Activity) through a reference which is passed by the user to my library class</p>