Using a Java Timer in an Android application has some drawbacks: one, it
invokes the callback on a worker thread, two, it stops if the process is
killed.
Take a look at AlarmManager - it's reliable even if the application is
killed, and uses an Android-specific notification mechanism when it fires.
http://developer.android.com/reference/android/app/AlarmManager.html
-- Kostya
25.01.2011 19:44, bklik пишет:
I have lots of issues with my egg timer application.
I started by just writing the application all in an action. That of
course didn't work because once the user left the application, it
would get garbage collected after a while and longer timers would
fail.
So, I tried a Service. My main Activity handles all the UI stuff and
binds to a Service. The user enters in the amount of time they want
the egg timer to fun for, and that time gets handed off to the
service.
The Service has a timer that deducts time every second until it
reaches zero, then plays a sound. Only, somehow it randomly never gets
there. Sometimes it'll work for a three hour countdown, other times
it'll stop working after only 30 minutes. I've put Log.d() all over
the place where things get stopped or destroyed but they never show
up.
Does a timer get stopped and garbage collected independed of an
Activity or Service? Is there a simple example of a persistent
countdown timer out there?
Thanks,
Brenton
--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com
--
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