title: AlarmManager gets killed on app destroy
body: <p>I have the following problem: I register my alarm manager in <code>onCreate</code>, It gets executed each minute now. <strong>However</strong> if i kill the app via the <code>Android taskmanager</code> (so the app state is <code>destoyed</code>) the <code>AlarmReceiver</code> stops excecuting. Why?</p>
  
  <p>My Code:</p>
  
  <p><strong>AlarmReceiver</strong></p>
  
  <pre><code>public class AlarmReceiver extends WakefulBroadcastReceiver {
  
  private AlarmManager mAlarm;
  private PendingIntent mAlarmIntent;
  
  @Override
  public void onReceive(Context context, Intent intent) {
      Intent service = new Intent(context, PortalPullService.class);
  
      startWakefulService(context, service);
  }
  
  public void setAlarm(Context context) {
      mAlarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
      Intent intent = new Intent(context, AlarmReceiver.class);
      mAlarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
  
      int interval = context.getResources().getInteger(R.integer.update_interval_in_mins) * 60 * 1000;
  
      mAlarm.setInexactRepeating(
              AlarmManager.ELAPSED_REALTIME_WAKEUP,
              SystemClock.elapsedRealtime() + interval,
              interval,
              mAlarmIntent);
  
      ComponentName reciever = new ComponentName(context, AlarmBootReceiver.class);
      PackageManager pm = context.getPackageManager();
  
      pm.setComponentEnabledSetting(reciever,
              PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
              PackageManager.DONT_KILL_APP);
  }
  
  public void cancelAlarm(Context context) {
      if(mAlarm != null) {
          mAlarm.cancel(mAlarmIntent);
      }
  
      ComponentName reciever = new ComponentName(context, AlarmBootReceiver.class);
      PackageManager pm = context.getPackageManager();
  
      pm.setComponentEnabledSetting(reciever,
              PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
              PackageManager.DONT_KILL_APP);
  }
  }
  </code></pre>
  
  <p><strong>PullService</strong></p>
  
  <pre><code>public class PortalPullService extends IntentService {
  
  private static final String LOG_TAG = "PortalPullService";
  
  public PortalPullService() {
      super(LOG_TAG);
  }
  
  @Override
  protected void onHandleIntent(Intent intent) {
  
  
      //TODO make request to ** check if new Infos are available, then send notification
  
      Helper.sendNotification(this, "Test", "Testnotification"); //My test if this works
  
      AlarmReceiver.completeWakefulIntent(intent);
  }
  
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;receiver android:name=".PortalUpdate.AlarmReceiver" /&gt;
  
  &lt;service
          android:name=".PortalUpdate.PortalPullService"
          android:exported="false" /&gt;   
  </code></pre>
  
  <p>The receiver gets registered via <code>new AlarmReceiver().setAlarm(this);</code></p>
  
  <p>I searched on sveral SO questions, but i can't find an answer... I don't know where is my fault...</p>
  
  <p>Thanks in advance ;)</p>