title: AlarmManager is not repeating
body: <p>I can't make AlarmManager repeating. I have tried a lot of examples, but for me they don't work. Alarm always fires only once, then nothing happens.
  I ran all examples on my device (android 4.4.2) and all the examples  work completely the same. Just one fire, and then nothing.
  Can anybody tell me what I'm doing wrong?
  Here is the code of the last example:
  Receiver:</p>
  <pre><code>package net.desme.alarmtest;
  
  import android.app.AlarmManager;
  import android.app.PendingIntent;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.PowerManager;
  import android.widget.Toast;
  
  public class Alarm extends BroadcastReceiver {
      public void onReceive(Context context, Intent intent)
      {
          PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
          PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, &quot;&quot;);
          wl.acquire();
          Toast.makeText(context, &quot;Alarm !!!!!!!!!!&quot;, Toast.LENGTH_SHORT).show(); // For example
          wl.release();
      }
  
      public void setAlarm(Context context)
      {
          AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
          Intent i = new Intent(context, Alarm.class);
          PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
          am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 6, pi); // Millisec * Second * Minute
      }
  
      public void cancelAlarm(Context context)
      {
          Intent intent = new Intent(context, Alarm.class);
          PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
          AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
          alarmManager.cancel(sender);
      }
  }
  </code></pre>
  <p>AndroidManifest.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;net.desme.alarmtest&quot; &gt;
  
      &lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:theme=&quot;@style/AppTheme&quot; &gt;
          &lt;activity
              android:name=&quot;.AlarmManagerActivity&quot;
              android:label=&quot;@string/app_name&quot; &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;receiver android:name=&quot;.Alarm&quot; android:process=&quot;:remote&quot; /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p>Activity:</p>
  <pre><code>package net.desme.alarmtest;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  
  public class AlarmManagerActivity extends Activity {
      Alarm alarm = new Alarm();
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_alarm_manager);
  
          findViewById(R.id.start_repeating).setOnClickListener(mStartRepeatingListener);
          findViewById(R.id.stop_repeating).setOnClickListener(mStopRepeatingListener);
      }
  
      private View.OnClickListener mStartRepeatingListener = new View.OnClickListener() {
          public void onClick(View v) {
              alarm.setAlarm(getApplicationContext());
          }
      };
  
      private View.OnClickListener mStopRepeatingListener = new View.OnClickListener() {
          public void onClick(View v) {
              alarm.cancelAlarm(getApplicationContext());
          }
      };
  }
  </code></pre>
  <p>Also i tried these:</p>
  <p><a href="https://developer.android.com/training/scheduling/alarms.html" rel="nofollow noreferrer">https://developer.android.com/training/scheduling/alarms.html</a>
  <a href="http://www.coderzheaven.com/2011/07/31/how-to-setup-a-repeating-alarm-in-android/" rel="nofollow noreferrer">http://www.coderzheaven.com/2011/07/31/how-to-setup-a-repeating-alarm-in-android/</a></p>
  <p>and much more but i cant post it because the red tip says that i need at least 10 reputation</p>
  <h2>EDIT</h2>
  <p>The problem was that in API 19+ all alarms are inexact. Here is what the documentation says:</p>
  <blockquote>
  <p>Note: as of API 19, all repeating alarms are inexact. If your
  application needs precise delivery times then it must use one-time
  exact alarms, rescheduling each time as described above. Legacy
  applications whose targetSdkVersion is earlier than API 19 will
  continue to have all of their alarms, including repeating alarms,
  treated as exact.</p>
  </blockquote>
  <p>And possible solutions:</p>
  <blockquote>
  <p>Note: for timing operations (ticks, timeouts, etc) &gt; it is easier and much more efficient to use Handler</p>
  <p>If your application wants to allow the delivery times to drift in order to guarantee that at least a certain time interval always elapses between alarms, then the approach to take is to use one-time alarms, scheduling the next one yourself when handling each alarm delivery.</p>
  </blockquote>