title: Android boot service never starts
body: <p>I'm new in Android programming.
  I have a receiver that starts a service at boot but it seems never started. Can you tell me what I'm doing wrong?
  I don't know how to debug it. Can you explain me how can I debug Android startup services too?</p>
  
  <p>Here is my code. Thank you in advance</p>
  
  <p>Recibidor.java:</p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.util.Log;
  import android.widget.Toast;
  
  public class Recibidor extends BroadcastReceiver {
  
     @Override
     public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "Iniciando Recibidor", Toast.LENGTH_LONG).show();
        final String TAG = "Recibidor";
        Log.i(TAG, "Iniciando Recibidor");
  
        if (intent.getAction().equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")) {
           Toast.makeText(context, "Iniciando Intent", Toast.LENGTH_LONG).show();
           Log.i(TAG, "Iniciando Intent");
  
           Intent servicio = new Intent();
           servicio.setAction("com.pruebas.Servicio");
           context.startService(servicio);
  
           Log.i(TAG, "Iniciando Servicio");
           Toast.makeText(context, "Iniciando Servicio", Toast.LENGTH_LONG).show();
         }
  
     }
  }
  </code></pre>
  
  <p>Servicio.java</p>
  
  <pre><code>package com.pruebas;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.util.Log;
  import android.widget.Toast;
  
  public class Servicio extends Service {
     private final String TAG = "Servicio";
  
  
     @Override
     public IBinder onBind(Intent arg0) {
        return null;
     }
  
     @Override
     public void onCreate() {
        super.onCreate();
        Log.i(TAG, "ON CREATE");
        Toast.makeText(this, "ON CREATE", Toast.LENGTH_LONG).show();
     }
  
     @Override
     public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "ON DESTROY");
        Toast.makeText(this, "ON DESTROY", Toast.LENGTH_LONG).show();
     }
  
     @Override
     public int onStartCommand(Intent intent, int flags, int startId) {
        startForeground(0, null);
        Log.i(TAG, "ON START COMMAND");
        Toast.makeText(this, "ON START COMMAND", Toast.LENGTH_LONG).show();
        return START_STICKY;
     }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.pruebas"
      android:versionCode="1"
      android:versionName="1.0"
      android:installLocation="internalOnly" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" /&gt;
  
     &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;application&gt;
          &lt;service android:name=".Servicio"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.pruebas.Servicio"/&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt; 
  
          &lt;receiver android:name=".Recibidor" android:enabled="true" android:exported="true" 
  android:permission="android.permission.RECEIVE_BOOT_COMPLETED"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
                  &lt;category android:name="android.intent.category.DEFAULT"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>