title: android: alarm task closed on application killed
body: <p>On my application I want to execute a task every few minutes, and for this I added an alarm manager to run on elapsed time. The code is simple:</p>
  
  <pre><code>    AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
      Intent i = new Intent(this, OnAlarmReceiver.class);
      PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
  
      mgr.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
              SystemClock.elapsedRealtime() + 1000 /* Initial run in 1 second */,
              OnBootReceiver.REPEAT_PERIOD, /* 10 minutes */
              pi);
  </code></pre>
  
  <p>of course I have the broadcast receiver:</p>
  
  <pre><code>public class OnBootReceiver extends BroadcastReceiver {
       //implementation here
  }
  </code></pre>
  
  <p>I run this code on main activity of my application and in a Broadcast (OnBootReceiver) to ensure that my code runs on app start and in each boot. </p>
  
  <p>My issue is when the operating system closes the bg applications. If I go to tasks manager and I run Clear Memory command, my application is closed and I don't get any alarm notification.</p>
  
  <p><strong>How do I keep receiving the alarm notifications on my code in this scenario?</strong></p>