title: Pass class object to service
body: <p>I'm new in android and java and encountered with one issue. I have an activity with methods and I want to use them in background. For background I used a Service class. The problem is that I cannot pass activity object to service constructor because it must not contains any params in it. I read how to send strings and doubles via intend but I cannot find how to pass activity class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class MainActivity extends Activity
  {
      @Override
      protected void onCreate( Bundle savedInstanceState ){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public void onStop(){
          super.onStop();
          startService(new Intent(this, MyService.class));
      }
  
      @Override
      public void onResume(){
          super.onResume();
          stopService(new Intent(this, MyService.class));
      }
  
      public void toast(String msg) {
          Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
      }
  }
  
  //---------------------------------------
  
  public class MyService extends Service
  {
      private MainActivity main;
  
      public MyService() {
      }
  
      @Override
      public void onCreate() {
          super.onCreate();
          main.toast("test");    // &lt;- here I want to use some method
      }
  
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thank you for any help!</p>