title: Why repeating tasks with alarm manager are not accurate on android?
body: <p>I'm developing an app which you can schedule your time and It reminds you on time just like google calendar. I use <code>AlarmManager</code> class and set a Repeating task to check Database every one minute and see if there is any alarm on that time or not.</p>
  
  <pre><code>@Override
  public void onReceive(Context context, Intent intent) {
  
      Calendar now = Calendar.getInstance();
  
      doRepeatingWorks(now.getTimeInMillis()); // Like Checking if one day passed to do some tasks
  
      checkDbIfThereIsSomeSchedule(now);
  }
  </code></pre>
  
  <p>And I call this to start alarm manager:</p>
  
  <pre><code>    public void setAlarm(Context context) {
              AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
              Intent intent = new Intent(context, AlarmReceiver.class);
              PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
              alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), G.ALARM_CHECK_INTERVAL_MILIS, pendingIntent);
  }
  </code></pre>
  
  <p>But it's inaccurate and sometimes I figure out that the task killer apps kill my alarm and make it totally worthless.</p>
  
  <p>Although using a <code>foregroundService</code> is battery consuming and it goes on user's nerve with the notification.</p>
  
  <p>Is there any solutions or alternatives for this problem?</p>