简体   繁体   中英

Android sdk & timers (Chronometer vs. Thread)

There are few built in ways to invoke a timer using the Android stack, A good example is the Chronometer .

I would like to integrate piece of code (A thread)that implements timer using the Thread.sleep() method

I plan to have a Service tat invoke this thread and communicate with it.

Are there any disadvantages of using the sleep() method over Chronometer?

It depends if it's sensitive to lifecycle. If your activity or service will be paused your timer will be stopped. Look into Alarm Manager . There are plenty of examples on this site about.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM