Pre API 19, the method of moving to update the widget faster than the minimum updatePeriodMillis time of 30 minutes, was to use AlarmManager and BroadcastReceiver to get the intent after the specified interval used in setting up AlarmManager.
Currently, using the code below, the widget is updated, but with Android 5.1 using .setRepeating () with a repeat interval of less than 60,000 ms, an interval of at least 60,000 ms will be automatically set.
Setting the alarm in onEnabled () widgets:
AlarmManager am= (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
then in AlarmManagerBroadcastReceiver onReceive ():
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "TAG");
The docs for setRepeating () say:
Note: According to API 19, all repeated alarms are inaccurate. If your application needs accurate delivery times, it should use one-time accurate alarms, each time reviewing the dates as described above. Deprecated applications whose targetSdkVersion was previously API 19 will still have all of their alarms, including repeated alarms that are considered accurate.
now also says:
Schedule a repeating signal. Note: for synchronization operations (ticks, timeouts, etc.) it is easier and more efficient to use Handler
So, how are you going to update Remoteviews Widgets with Handler? How do you stop it when the device sleeps to save battery?
Are there any other suggested ways to update the widget?