title: Android Application not running at startup
body: <p>I have a basic Android application that is supposed to reboot the phone continuously a set number of times.  In order to do this, I need the application to be started upon phone startup.  In order to that, I essentially followed the instructions found <a href="https://stackoverflow.com/questions/6391902/how-to-start-an-application-on-startup">here</a>, adding the permissions to the manifest and creating a BroadcastReceiver class that starts the activity.  Here is some of my relevant code:</p>
  
  <pre><code>public class StartMyServiceAtBootReceiver extends BroadcastReceiver {
  
  @Override
  public void onReceive(Context context, Intent intent) {
      System.out.println("StartMyServiceAtBootReceiver called.");
  
      if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
          // Intent activityIntent = new Intent("com.example.rebooter.MainActivity");
          Intent activityIntent = new Intent(context,MainActivity.class);
          activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          context.startActivity(activityIntent);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>From the manifest file:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.rebooter"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="15" /&gt;
  
  &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
  
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" &gt;
          &lt;action android:name="android.intent.action.MAIN" /&gt;
          &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
      &lt;/activity&gt;
  
      &lt;service
          android:name=".RebootManager"
          android:label="Reboot Manager" &gt;
          &lt;action android:name="com.example.rebooter.RebootManager" /&gt;
      &lt;/service&gt;
  
      &lt;receiver android:name=".StartMyServiceAtBootReceiver"
          android:enabled="true"
          android:exported="true"
          android:label="StartMyServiceAtBootReceiver" &gt;
          &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
      &lt;/receiver&gt;       
  
  &lt;/application&gt;
  </code></pre>
  
  <p>In the Eclipse emulator, the application appears to be working properly.  That is, though my emulator isn't rooted and the phone doesn't execute the reboot commands correctly, I do see that, upon startup, the correct activity is started.</p>
  
  <p>Now, when I'm trying it on a particular system running Android 4.0.4, everything in the application is working properly EXCEPT boot upon startup.  Any ideas?  </p>
  
  <p>I tried to eliminate the possibility of any hardware problems (since I'm not using a commercially-released phone) by installing another application that boots upon startup and confirming that it does indeed boot upon startup, and it does indeed show up under running apps as a cached process after startup.</p>
  
  <p>I would appreciate any help.  Let me know if you need any additional information.</p>