How To Properly Update A Widget In Android 8.0 - Oreo - API 26 : <p>Let's say I have a widget for an app that has targetSDKVersion set to 26. This widget takes between 100ms and 10s to update. Most of the time under 1s. Before Android O, if onUpdate() was called on my AppWidgetProvider, I could launch a background service to update this widget. However, Android O returns an IllegalStateException if you attempt that behavior. The obvious solution of starting a foreground service seems like an extreme measure for something that will be done in under 10s 99% of the time.</p>

<p>Possible solutions</p>

<ul>
<li>Start a foreground service to update the widget. Annoy the user with a notification that will be gone in 10s.</li>
<li>Use JobScheduler to schedule a job as quickly as possible. Your widget may or may not get updated for a while.</li>
<li>Attempt to do the work in a broadcast receiver. Lock up the UI thread for any other apps. Yuck.</li>
<li>Attempt to do work in the widget receiver. Lock up the UI thread for any other apps. Yuck.</li>
<li>Abuse GCM to get a background service running. A lot of work and feels hacky.</li>
</ul>

<p>I don't personally like any of the above solutions. Hopefully I'm missing something. </p>

<p>(Even more frustrating is that my app is already loaded into memory by the system calling onUpdate(). I don't see how loading my app into memory to call onUpdate(), but then not giving my app 1s to update the widget off the UI thread is saving anyone any battery life.)</p>
