title: AlarmManager stops working after a few days
body: <p>I have a service which should be run for example every 1 minute. I used a broadcast receiver and AlarmManager to make this work. And also I call PowerManger.aquire() to make sure cpu doesn't sleep before the service starts. For first 2 or 3 days the app runs okay but after that the service doesn't get started. Sounds alarmManager doesn't start it. Any Idea why?</p>
  
  <pre><code>public class MyReceiver extends BroadcastReceiver {
      PowerManager pawerManager;
      public static PowerManager.WakeLock wakeLock=null;
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
           pawerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
           wakeLock = pawerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "");
           wakeLock.acquire();
           Intent serviceIntent=new Intent(context,MyService.class);
           context.startService(serviceIntent);
      }
  }
  </code></pre>
  
  <p>And The Service:</p>
  
  <pre><code>public class MyService extends Service {
      void releaseTheLock(){
          if (MyReceiver.wakeLock != null){
              MyReceiver.wakeLock.release();
              MyReceiver.wakeLock=null;
          }
      }
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub      
          return null;
      }
      @Override
      public void onCreate() {
          // TODO Auto-generated method stub      
          super.onCreate();       
      }
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          // TODO Auto-generated method stub
          final Context serviceContext=this;      
          new Thread(new Runnable() {         
              @Override
              public void run() {
                  // TODO Auto-generated method stub      
                      /*
                         Do something
                      */
                      //Now set the timer
                      long currntTime = System.currentTimeMillis();
                      AlarmManager mgr=(AlarmManager)getApplicationContext().getSystemService(Context.ALARM_SERVICE);
                      Intent i= new Intent(serviceContext, MyReceiver.class);
                      PendingIntent pi=PendingIntent.getBroadcast(serviceContext, 0, i, 0);                       
                      mgr.set(AlarmManager.RTC_WAKEUP, currntTime + 60000 , pi);                      
                      stopSelf();
                      releaseTheLock();
                      return;                 
  
              }
          }).start();
      return START_STICKY;
      }   
  }
  </code></pre>
  
  <p>And here's the receiver registration in manifest:</p>
  
  <pre><code>&lt;receiver android:name=".TimeReceiver"&gt;&lt;/receiver&gt;
  </code></pre>