title: Start Application on Startup in Android
body: <p>I am trying to launch the main activity (which is the only activity) named as "MainActivity" when the Android OS starts. The app is installed on the internal storage but it says Unfortunately, The app(Name of app) has stopped. I am using the Boot Receive code as below</p>
  
  <p>My MainActivity code in .java file</p>
  
  <pre><code>public class BootUpReceiver extends BroadcastReceiver
  {
  
      @Override
      public void onReceive(Context context, Intent intent) {
              Intent i = new Intent(context, MainActivity.class);  
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              context.startActivity(i);  
      }
  }
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>   &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  
        &lt;receiver android:enabled="true" android:name=".BootUpReceiver"
      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;
  </code></pre>