title: Updating a Widget at short intervals using API 19+
body: <p>Pre API 19, the go-to method for updating a Widget faster than the <code>updatePeriodMillis</code> minimum time of 30 minutes was to use an <code>AlarmManager</code> and a <code>BroadcastReceiver</code> to receive the Intent after the specified interval used when setting up the AlarmManager. </p>
  
  <p>Currently, using the below code, the Widget is updated, but as of Android 5.1, using .setRepeating() with a repeat interval of less than 60000ms will automatically have its interval set to at least 60000ms.</p>
  
  <p>Setting alarm in Widgets onEnabled():</p>
  
  <pre><code>AlarmManager am= (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
  PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
  //After after 3 seconds
  am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 3000, 1000 , pi);
  </code></pre>
  
  <p>then in the AlarmManagerBroadcastReceiver's onReceive():</p>
  
  <pre><code>PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
  PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG");
  //Acquire the lock
  wl.acquire();
  
  /* 
   * ......
   * Update Widgets RemoteViews
   */
  
  wl.release();
  </code></pre>
  
  <p>In the docs for <a href="http://developer.android.com/reference/android/app/AlarmManager.html#setRepeating(int,%20long,%20long,%20android.app.PendingIntent)">setRepeating()</a> it 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>it also now states:</p>
  
  <blockquote>
    <p>Schedule a repeating alarm. Note: for timing operations (ticks, timeouts, etc) it is easier and much more efficient to use <code>Handler</code></p>
  </blockquote>
  
  <p>So how would you go about updating the Widgets Remoteviews using a Handler? How would you get it to stop when the device is put to sleep to conserve battery?</p>
  
  <p>Are there any other suggested ways to update a Widget?</p>