title: Android calling class functions from second class
body: <p>How can I call a function defined in class#A from class#B? Class#B extends AsynchTask and fetches remote data from a web service. The class#A function I am attempting to call from class#B is used to send the retrieved remote data for Class#A to display.</p>
  
  <p>I am trying to pass the current instance of class#A to class#B using <code>this</code> but that just passes the context so the functions are not recognized.</p>
  
  <p>I also tried using <code>static</code> but as the function runs a new thread, defining the function as static generates a compiler error.</p>
  
  <p>The code I am trying to call is as follows:</p>
  
  <pre><code>public void test(List&lt;DATA&gt; Data){
          this.Data = Data;
          runOnUiThread(new Runnable() {          
  
              @Override
              public void run() {
                  // TODO Auto-generated method stub
                  for(DATA data : MainActivity.this.Data){
                      Toast.makeText(MainActivity.this, data.title, Toast.LENGTH_SHORT).show();
                  }
              }
          });
      }
  </code></pre>