title: Android: start service with parameter
body: <p>To start my service from an Activiy I use <code>startService(MyService.class)</code>. This works great, but in a special case the service should be started differently. I want to pass some parameters to the service start.</p>
  
  <p>I tried the following in my Activity:</p>
  
  <pre><code>Intent startMyService= new Intent();
  startMyService.setClass(this,LocalService.class);
  startMyService.setAction("controller");
  startMyService.putExtra(Constants.START_SERVICE_CASE2, true);
  
  startService(startMyService);
  </code></pre>
  
  <p>In my Service I use:</p>
  
  <pre><code>public class MyIntentReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
  
          if (intent.getAction().equals("controller")) 
          {
                  // Intent was received                               
          }
  
      }
  } 
  </code></pre>
  
  <p>The IntentReceiver is registered in onCreate() like this:</p>
  
  <pre><code>IntentFilter mControllerIntent = new IntentFilter("controller");
  MyIntentReceiver mIntentReceiver= new MyIntentReceiver();
  registerReceiver(mIntentReceiver, mControllerIntent);
  </code></pre>
  
  <p>With this solution the service starts but the intent is not received. <strong>How can I start a Service and pass my parameters?</strong> </p>
  
  <p>Thanks for your help!</p>