Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For a widget it usually doesn't make sense to keep a service running all the time, you usually update the widget periodically. </p> <p>The easiest way to do this and to be battery efficient is to schedule an intent using <code>AlarmManager</code> and <a href="http://developer.android.com/reference/android/app/AlarmManager.html#setInexactRepeating%28int,%20long,%20long,%20android.app.PendingIntent%29" rel="nofollow">setAlarmInexactRepeating</a>:</p> <blockquote> <p>Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour. These alarms are more power-efficient than the strict recurrences supplied by setRepeating(int, long, long, PendingIntent), since the system can adjust alarms' phase to cause them to fire simultaneously, avoiding waking the device from sleep more than necessary.</p> </blockquote> <p>The intent should trigger a BroadcastReceiver which in turn should trigger your service to update the widget. Using <code>IntentService</code> is usually a good choice for that.</p> <p>If you need more control over the intent scheduling, you can also set the alarms yourself in when the service is finished with updating the widget, and supply <code>RTC</code> or <code>ELAPSED_REALTIME</code> as the type of alarms. Both types won't wake up the device if it's sleeping. If the device is not sleeping (but locked) you'll effectively piggy back on other events that woke the device.</p> <p>If you really need to update as soon as the device is unlocked, the <a href="http://developer.android.com/reference/android/content/Intent.html#ACTION_USER_PRESENT" rel="nofollow">ACTION_USER_PRESENT</a> broadcast might be what you need, but I'd still recommend to implement that as an addition to scheduling a periodic update.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload