The process the service is running in might be killed at any time by
the platform and later restarted automatically.

On Jan 15, 1:39 pm, richf <[email protected]> wrote:
> Can I rely on Timer and TimerTask to work properly on Android?
>
> I have a background Service with a single Timer, and I schedule
> (possibly
> multiple) TimerTask's via Timer.schedule()
>
> At the beginning of each implemented TimerTask.run() method, I check
> the
> TimerTask.scheduledExecutionTime() and compare it with the current
> time.
> Sometimes things are fine, and the difference is a small number of
> ms.  But
> sometimes things are nowhere near fine, and the invocation of my
> TimerTask is
> *way* late -- like multiple hours late.
>
> Can an Android phone go into some deep sleep mode when it doesn't
> think
> anything is going on that would cause a TimerTask to be so late?  Can
> I not
> reliably use TimerTask for scheduling events, and should I be using
> some
> Android-specific means (e.g. the AlarmManager, or a Handler) instead?
>
> I've searched around a bit, and while I can find numerous posts
> suggesting
> Android-specific timing mechanisms, I have not found anything that
> says that
> java.util.TimerTask shouldn't be sufficient, the Android docs include
> no kinds
> of qualifiers, and this post (from Mark Murphy, who's written several
> good
> Android books) specifically mentions it as being available:
>
> http://groups.google.com/group/android-developers/browse_thread/threa...
>
> Thanks for any help anyone may be able to provide.
>
> - Rich
-- 
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