How can I get a reference to the Activity that called a method?
<p>I have a class that extends AsyncTask to send an ethernet message. When created and called within my MainActivity it works fine:</p>

<pre><code>new SendCommandTask(MainActivity.this).execute(ipAddress, portNum, message);
</code></pre>

<p>However, I would like to embed this within a method in a new class instead...</p>

<pre><code>public class NewClass{

   String ipAddress;
   String portNum;
   String command;

   public NewClass(String ip, String pn, String, c){
      ipAddress = ip;
      portNum = pn;
      command = c;
   }
   public send(){
      SendCommandTask(MainActivity.this).execute(ipAddress, portNum, command);
   }
}
</code></pre>

<p>... and call the method directly from my MainActivity:</p>

<pre><code>NewClass newClass = new NewClass;    
NewClass.send();
</code></pre>

<p>I have tried passing the activity as another parameter in the constructor, but the method pukes when I do that. Is there another way to refer to the calling Activity in my NewClass? Or am I stuck running the AsyncTask from the MainActivity?
(I hope this makes sense, I'm very new to Java and OO programming in general.) Any help is very much appreciated!</p>
