安卓sdk&计时器(计时器与线程)

发布于 2024-09-13 01:05:52 字数 287 浏览 2 评论 0原文

使用 Android 堆栈调用计时器的内置方法很少, 一个很好的例子是 Chronometer

我想集成使用 Thread.sleep() 方法实现计时器的代码段(线程),

我计划让一个服务调用该线程并与其通信。

与 Chronometer 相比,使用 sleep() 方法有什么缺点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唔猫 2024-09-20 01:05:52

这取决于它是否对生命周期敏感。如果您的活动或服务将暂停,您的计时器将停止。查看闹钟管理器。该网站上有很多相关示例。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文