title: Start Service schedule without reboot?
body: <p>I'm coding my first app that uses a service, following the tutorial/guide here <a href="http://www.vogella.com/articles/AndroidServices/article.html" rel="nofollow">http://www.vogella.com/articles/AndroidServices/article.html</a>
  I've got my service working and it describes making a broadcast receiver for BOOT_COMPLETED which works and allows me to run the service every few minutes.</p>
  
  <p>The problem I have is that it doesn't work until the user reboots their phone.  The service starts with the activity, but seems to die with the activity as well unless the device has been rebooted.  </p>
  
  <p>Is there any way to start the scheduler from the activity when it's first run without rebooting?</p>
  
  <p>My code for the scheduler is as follows:</p>
  
  <pre><code>public class ScheduleReceiver extends BroadcastReceiver {
  
      // Restart service every 30 seconds
      private static final long REPEAT_TIME = 1000 * 60; // check every minute.  
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.d("schedulereceiver", "starting schedule");
          AlarmManager service = (AlarmManager) context
                  .getSystemService(Context.ALARM_SERVICE);
          Intent i = new Intent(context, StartServiceReceiver.class);
          PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
                  PendingIntent.FLAG_CANCEL_CURRENT);
          Calendar cal = Calendar.getInstance();
          // Start 30 seconds after boot completed
          cal.add(Calendar.SECOND, 30);
          //
          // Fetch every 30 seconds
          // InexactRepeating allows Android to optimize the energy consumption
          service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
                  cal.getTimeInMillis(), REPEAT_TIME, pending);
  
          // service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
          // REPEAT_TIME, pending);
  
      }
  }
  </code></pre>
  
  <p>My Manifest file looks like this:
      
      </p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
      &lt;application
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name" &gt;
  
          &lt;activity
              android:name=".ProximityActivity"
              android:label="@string/app_name" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;service
              android:name=".ProximityService"
              android:enabled="true"
              android:icon="@drawable/ic_launcher"
              android:label="@string/service_name" &gt;
          &lt;/service&gt;
  
          &lt;receiver android:name="ScheduleReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;receiver android:name="StartServiceReceiver" &gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>