G'day mate,

I don't know if you have read this section of the documentation, but I
am reposting it here in case you have missed it:

---------------------

The updatePeriodMillis attribute defines how often the App Widget
framework should request an update from the AppWidgetProvider by
calling the onUpdate() method. The actual update is not guaranteed to
occur exactly on time with this value and we suggest updating as
infrequently as possible—perhaps no more than once an hour to conserve
the battery. You might also allow the user to adjust the frequency in
a configuration—some people might want a stock ticker to update every
15 minutes, or maybe only four times a day.

Note: If the device is asleep when it is time for an update (as
defined by updatePeriodMillis), then the device will wake up in order
to perform the update. If you don't update more than once per hour,
this probably won't cause significant problems for the battery life.
If, however, you need to update more frequently and/or you do not need
to update while the device is asleep, then you can instead perform
updates based on an alarm that will not wake the device. To do so, set
an alarm with an Intent that your AppWidgetProvider receives, using
the AlarmManager. Set the alarm type to either ELAPSED_REALTIME or
RTC, which will only deliver the alarm when the device is awake. Then
set updatePeriodMillis to zero ("0").

---------------------

I avoid battery-draining apps like a digital clock, myself, but if I
was to do this I would not use a handler within the widget for what
you have described. If I was creating this clock widget I would do one
of these things:

1. Set an alarm using AlarmManager that updates the widget every
second (if you broadcast an update request, the widget may not get it
immediately, so maybe the alarm manager should simply invoke the
service that does the update). Definitely read the AlarmManager
documentation if you have not done so already.

2. Modify the service to update every second in either a separate
thread or a handler (using Handler.postAt() method). I would start the
service normally within the widget, so I would replace your code with:

    public void onReceive(Context context, Intent intent)
    {
        mContext = context;

        Intent intent = new Intent(mContext, UpdateService.class);
        mContext.startService(intent);
    }


On Fri, Mar 18, 2011 at 2:11 PM, hardrock <[email protected]> wrote:
> Thanks, Mr. Mark
>
> More Questions.
>
> 1. AppWidget extends BroadcastReceiver.
>   This meams that even *ANY* appwidget cannot guarantee from system-
> kill.
>   Isn't there any way to prevent time-freezing of digital clock
> widget ?
>
> 2. I think that it's better to use AlarmManager than
> ACTION_TIME_TICK(because receiver die) every minute.
>   But there is some problem.
>   If the system kill my clock widget during working AlarmManager
> every minute,
>   it NEVER be called onDisabled() or onDelete() method. (i.e. It can
> not cancel alarm.)
>   As a result, my clock widget already die by system-kill but alarm
> still alive.
>   Isn't there any way to cancel alarm when system kill my clock
> widget.
>
> 3. For battery consumption,
>   which is better between using AlarmManager and using
> ACTION_TIME_TICK every minute.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to