title: How to start an activity via a service after rebooting
body: <p>I need my app to start running (in the background) after rebooting the device. Here's what I've come up with till now (after taking a lot of help from here...)</p>
  
  <p>This is my BootUpReceiver making use of broadcastreceiver:</p>
  
  <pre><code>public class BootUpReceiver extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Intent serviceIntent = new Intent(context, RebootService.class);
          serviceIntent.putExtra("caller", "RebootReceiver");
          context.startService(serviceIntent);
      }
  }
  </code></pre>
  
  <p>This is the service class:</p>
  
  <pre><code>public class RebootService extends IntentService{
  
      public RebootService(String name) {
          super(name);
          // TODO Auto-generated constructor stub
  }
  
  protected void onHandleIntent(Intent intent) {
  
          Intent i = new Intent(getBaseContext(), MainActivity.class);  
          i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  
          String intentType = intent.getExtras().getString("caller");
          if(intentType == null) 
              return;
          if(intentType.equals("RebootReceiver")) 
              getApplication().startActivity(i);            
      }
  }
  </code></pre>
  
  <p>THis is my android manifest:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;receiver
          android:name=".BootUpReceiver"
          android:enabled="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;service android:name=".RebootService"/&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p>The problem is, When I install this on my phone and reboot, the app crashes: It says, "Transfer has stopped working". After I press the OK button, when I check the app info, the app is running.</p>
  
  <p>I'm new to android and I'm not sure what is going on. Am I supposed to add any more permissions?</p>
  
  <p>Kindly help.
  TIA</p>