title: Android start service using broadcast receiver
body: <p>I am implementing the following code, in which I want to start a service using broadcast receiver. The toast in the broadcast receiver is working fine but the service is not executing.
  Can anyone tell me where I went wrong?</p>
  
  <pre><code>MyReceiver.class
  public class MyReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context arg0, Intent arg1) {
          // TODO Auto-generated method stub
          //Toast.makeText(arg0, "Service", Toast.LENGTH_LONG).show();
          Intent myIntent = new Intent(arg0,MyS.class);
          arg0.startService(myIntent);
      }
  }
  
  
  MyS.class
  public class MyS extends Service {
  
      @Override
      public IBinder onBind(Intent arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // TODO Auto-generated method stub
          Toast.makeText(getBaseContext(), "Service started", Toast.LENGTH_LONG).show();
          return START_STICKY;
      }
  }
  
  
  AndroidManifest.xml
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.test.p"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
         &lt;service android:enabled="true"
             android:name=".MyS" &gt;
             &lt;intent-filter&gt;
                 &lt;action android:name="com.test.p.MyS" &gt;
                 &lt;/action&gt;
             &lt;/intent-filter&gt;
         &lt;/service&gt;
  
         &lt;receiver android:enabled="true"
             android:name=".MyReceiver" &gt;
             &lt;intent-filter&gt;
                 &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
             &lt;/intent-filter&gt;
         &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>