1

I wanted to make a widget that updates every sec(more battery consumption) or min(less battery consumption).

I followed as in this thread

, but runs only in every 30mins.

I configured that, once onUpdate is run, it updates in 1mins and onReceived is run in every 30mins.

Can anyone tell me what I am doing wrong?

Community
  • 1
  • 1
Kapil M
  • 63
  • 1
  • 9
  • 1
    You are not showing any code, so besides the missing code we do not know what you did wrong... – Veger Dec 19 '13 at 12:23

2 Answers2

2

From my experience AlarmManager doesn't work well (or at all) with intervals lower than 1 minute. Besides:

Note: The Alarm Manager is intended for cases where you want to have your application code run at a specific time, even if your application is not currently running. For normal timing operations (ticks, timeouts, etc) it is easier and much more efficient to use Handler.

Moreover:

Note: Beginning with API 19 (KITKAT) alarm delivery is inexact: the OS will shift alarms in order to minimize wakeups and battery use. There are new APIs to support applications which need strict delivery guarantees; see setWindow(int, long, long, PendingIntent) and setExact(int, long, PendingIntent). Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.

XorOrNor
  • 8,868
  • 12
  • 48
  • 81
0

You are doing nothing wrong, the widget service indeed only updates every 30 minutes(minimum).

To make it update faster you need to use AlarmManager, or your own application that will call the service. Unlike soulreaver answer, the alarm manager does work with times less then 1 minute.

Community
  • 1
  • 1
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • I this this is working: am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60 * 10, pi); // Millisec * Second * Minute changed the code and its working. – Kapil M Dec 19 '13 at 12:59
  • @soulreaver read your own answer: "Applications whose targetSdkVersion is earlier than API 19 will continue to see the previous behavior in which all alarms are delivered exactly when requested.", if I target below version 19 I will not be effected. Also I am not sure if it's matter in this case. – Ilya Gazman Dec 19 '13 at 14:41
  • Neither me, I don't know which APIs you target. I'm only saying it won't work on devices witch KITKAT installed. I would never release app which is uncompatible with newer devices in the moment it is released. – XorOrNor Dec 19 '13 at 15:01