As stated in the Android Dev Guide, if you want the widget to update more often, you should use the AlarmManager to set alarms that won't wake the device.
Basically: do not use the standard mechanisms provided by the AppWidgetProvider class, and it is easy to configure it using android: updatePeriodMillis in an XML file.
I apologize, but the manual simply says: "Use AlarmManager, use RTC or ELAPSED_REALTIME , ...", but EXACTLY, that I send the intention to simply update my widget, it is absent !!!
Can someone PendingIntent specify the code I need to form a PendingIntent that mimics the default behavior? I donβt know how to get widget IDs, what action should I use, etc ... The garden guide stops explaining at this moment! What is needed as additional features that require action?
In case someone is wondering why I want to update more often than 30 minutes: my widget shows when the next bus leaves for the station. There is a bus every 20 minutes, so I have two options: update the widget every minute, showing the departure time of the next bus (what I want!) Or, not so good, specify the departure time of the next bus so I will need to update at least every 20 minutes!
Now: when the device is sleeping, of course, this should never wake him up - so my understanding of this section in the dev manual is that this is the right way to implement it; Does anyone think I'm wrong? Oh, one more thing I would like to know: if the device is sleeping, when the widget needs to be updated, and my alarm does not come out because of the sleeping device, will it be updated IMMEDIATELY when it wakes up ???
Thanks for the help!
PS: Iβm really wondering why the definition of the xml of the widget provider does not allow you to simply indicate "do not wake the device" with a logical switch ... it would make life a lot easier in the first place! Which widget do you need to wake the device anyway ???; -)
This is how I got so far, but it does not work - nothing happens:
private void startAlarm(Context pContext) { Log.d(TAG, "startAlarm"); AlarmManager am = (AlarmManager) pContext.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent("android.appwidget.action.APPWIDGET_UPDATE"); intent.setClass(pContext, getClass()); PendingIntent pi = PendingIntent.getBroadcast(pContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, pi); }