title: Android- How to send data from activity to service?
body: <p>In my application I'm trying to send data from my <code>MainActivity.class</code> to a service called <code>bgservice.class</code>. This is my following code:</p>
  
  <p>MainActivity.class:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Intent serviceIntent = new Intent(bgservice.class.getName());
    serviceIntent.putExtra("UserID", "123456");
    this.startService(serviceIntent);
  }
  </code></pre>
  
  <p>bgservice.class:  </p>
  
  <pre><code>@Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
    String userID = intent.getStringExtra("userID");
    System.out.println(userID);
    Toast.makeText(this,userID, Toast.LENGTH_LONG).show();
    return START_STICKY;
  
  }
  </code></pre>
  
  <p>but I'm not getting the data in the service class. these are the following error I get:</p>
  
  <blockquote>
    <p>02-25 09:05:41.166: E/AndroidRuntime(2633): </p>
    
    <p>java.lang.RuntimeException: Unable to start activity<br>
    ComponentInfo{com.microapple.googleplace/com.microapple.googleplace.
    MainActivity}: java.lang.IllegalArgumentException: Service Intent must
    be   explicit: Intent { act=com.microapple.googleplace.bgservice (has
    extras) }</p>
  </blockquote>
  
  <p>AndroidManifest.xml:</p>
  
  <pre><code>     ...
      &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
  
  
  
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;service android:enabled="true" android:name=".bgservice" /&gt;
  &lt;/application&gt;
  ....
  </code></pre>