title: get Activity's reference from a Service
body: <p>I need to get a reference to the main Activity from a Service.</p>
  
  <p>This is my design:</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity{
  private Intent myIntent;
  onCreate(){
   myIntent=new Intent(MainActivity.this, MyService.class);
  
   btnStart.setOnClickListener(new OnClickListener(){
    public void onClick(View V){
     startService(myIntent);
     });
  }}
  </code></pre>
  
  <p><strong>MyService.java</strong></p>
  
  <pre><code>class MyService extends Service{
  
   public IBinder onBind(Intent intent) {
    return null;
   }
  
   onCreate(){
   //Here I need to have a MainActivity reference
   //to pass it to another object
   }
  }
  </code></pre>
  
  <p>How can I do this?</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>Thanks to all for the answers!
  This app is a web server, that at this moment works only with threads, and I want to use a service instead, to make it work also in the background.
  The problem is that I have a class that is responsible for getting the page from assets, and to do this operation I need to use this method:</p>
  
  <pre><code>InputStream iS =myActivity.getAssets().open("www/"+filename); 
  </code></pre>
  
  <p>At this moment my project has only one Activity and no services, so I can pass the main activity's reference directly from itself:</p>
  
  <pre><code>WebServer ws= new DroidWebServer(8080,this);
  </code></pre>
  
  <p>So, in order to make this app work with a service, what should I change in my design?</p>