title: Alarmmanager wont work after reboot on Android?
body: <p>Hi I know this question has been asked before but I dont think it has in this context. I have a application which runs through a DB and then according to times in that DB sets repeating alarms every 24 Hours. </p>
  
  <p>The Alarms work but as soon as I reboot I get one Alarm straight away then no more until I open the app again. </p>
  
  <p>I have the following <strong>two methods</strong> which set up the alarm. The to_reminder method is run from my onCreate method in my main Activity. </p>
  
  <pre><code>public void to_reminder()
  {
      helper = new TaskDBHelper(Meds2.this);
      SQLiteDatabase sqlDB = helper.getReadableDatabase();
      Cursor cursor = sqlDB.query(TaskContract.TABLE,
              new String[]{TaskContract.Columns._ID, TaskContract.Columns.TASK, TaskContract.Columns.DATE},
              null, null, null, null, null);
  
      cursor.moveToFirst();
  
      //Cancel All Alarms
      Intent intent=new Intent(this,BackgroundService.class);
      AlarmManager manager=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
      PendingIntent pendingIntent=PendingIntent.getService(this,
              0,intent, 0);
      try {
          manager.cancel(pendingIntent);
          pendingIntent.cancel();
      } catch (Exception e) {
          Log.e(TAG, "AlarmManager update was not canceled. " + e.toString());
      }
  
  
      while (!cursor.isAfterLast()) { // Loop until all vales have been seen
  
          String time = cursor.getString(2);
          String[] parts = time.split(":"); //Split  String Value stored in db
          String part1 = parts[0]; // hour
          String part2 = parts[1]; // minute
          int hr = Integer.parseInt(part1);
          int min = Integer.parseInt(part2);
  
          Random generator = new Random();
  
          setUpAlarm(hr,min);
  
          Log.e(TAG, "DATE VALUE TIME IS " + part1 +"--" +part2 + " Random Number is: " + generator.nextInt()); //log part one and two to make sure time is right
          cursor.moveToNext();
      }
  }
  
  public void setUpAlarm(int hr, int min){
  
      Random generator = new Random();
      Intent intent=new Intent(this,BackgroundService.class);
  
      AlarmManager manager=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
  
      PendingIntent pendingIntent=PendingIntent.getService(this,
              generator.nextInt(),intent, PendingIntent.FLAG_ONE_SHOT);
  
      long _alarm = 0;
  
      Calendar now = Calendar.getInstance();
      Calendar cal=Calendar.getInstance();
      cal.set(Calendar.HOUR_OF_DAY, hr);
      cal.set(Calendar.MINUTE,min);
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);
  
      if(cal.getTimeInMillis() &lt;= now.getTimeInMillis())
          _alarm = cal.getTimeInMillis() + (AlarmManager.INTERVAL_DAY+1);
      else
          _alarm = cal.getTimeInMillis();
  
      manager.setRepeating(AlarmManager.RTC_WAKEUP,_alarm,AlarmManager.INTERVAL_DAY,pendingIntent);
  
  }
  </code></pre>
  
  <p>My <strong>Alarm Receiver</strong> Class simply starts BackgroundService</p>
  
  <pre><code>public class AlarmReceiver extends BroadcastReceiver {
  
  
  @Override
  public void onReceive(Context context, Intent intent)
  {
  
      Intent background = new Intent(context, BackgroundService.class);
  
      context.startService(background);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My <strong>Background service</strong> sets up the notification.</p>
  
  <pre><code>public void mainMeth(){
  
  
      Intent browserIntent = new Intent(this,Meds2.class);
      PendingIntent pendingIntent = PendingIntent.getActivity(
              context,
              0,
              browserIntent,
              0);
  
      NotificationCompat.Builder builder =
              new NotificationCompat.Builder(context)
                      .setSmallIcon(R.drawable.cast_ic_notification_2)
                      .setContentTitle("Medication Reminder")
                      .setContentInfo("Time")
                      .setContentIntent(pendingIntent)
                      .setContentText("Open Application" )
                      .setDefaults(Notification.DEFAULT_SOUND)
                      .setAutoCancel(true)
                      .setVibrate(new long[]{200, 200, 200, 200}) //set virbrate &amp; color of led
                      .setLights(Color.BLUE, 3000, 3000);
  
      NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
      nManager.notify(getID(), builder.build());
  
  }
  </code></pre>
  
  <p>My <strong>Manifest</strong> has the following code in it too</p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/&gt;
  
  &lt;receiver android:name=".AlarmReceiver"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p>Any help on how I can get this to work after a reboot would be appreciated thanks. </p>