title: Using AlarmManager to run a Service when App is not running
body: <p>I want to schedule a call to a  <code>Service</code> every X time:</p>
  
  <p>In my activity I created alarm:</p>
  
  <pre><code>        // OnCreate()
          alarmIntent = new Intent ( this, AlarmReceiver.class );
          pendingIntent = PendingIntent.getBroadcast( this.getApplicationContext(), 1, alarmIntent, 0 );
          alarmManager = ( AlarmManager ) getSystemService( ALARM_SERVICE );
          alarmManager.setRepeating( AlarmManager.RTC_WAKEUP, ( 30 * 1000 ),( 30 * 1000 ), pendingIntent );
  </code></pre>
  
  <p>and In the Receiver :</p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
  
      private static final String DEBUG_TAG = "AlarmReceiver";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.d(DEBUG_TAG, "Recurring alarm; requesting download service.");
  
          // start the download
          Intent downloader = new Intent(context, MyService.class);
          context.startService(downloader);
      }
  
  }
  </code></pre>
  
  <p>In <code>AndroidManifest.xml</code> I register it: </p>
  
  <pre><code> &lt;receiver android:name="com.myapp. AlarmReceiver"&gt;&lt;/receiver&gt;
  </code></pre>
  
  <p>It works only when <strong>app is running</strong>...How can I schedule that so it work even If user close the app?</p>