跨多个活动的计时器

发布于 2024-09-07 11:06:57 字数 98 浏览 1 评论 0原文

我有一个带有多项活动的 Android 应用程序。我需要在第一个活动开始时启动计时器,并在最后一个活动开始时结束计时器并显示经过的时间。我如何使用 Asynctask 来执行此操作。

i have an android app with several activities. I need to start a timer when the first activity starts and end the timer when the last activity starts and show the elapsed time. How can i use Asynctask to do this.

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

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

发布评论

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

评论(2

吝吻 2024-09-14 11:06:57

子类 Application,声明一个 public static long started;,它将由 中的第一个 Activity 分配给 System.currentTimeMillis(); onCreate() 或 onResume()。让最后一个Activity读取该值并计算增量。
如果您绝对想使用 AsyncTask(我认为在这种情况下无关紧要),那么您至少需要一个中介服务。

Subclass Application, declare a public static long started; which will be assigned to System.currentTimeMillis(); by the first Activity in onCreate() or onResume(). Have the last Activity read the value and calculate delta.
If you absolutely want to use AsyncTask (which I think is irrelevant in this case), you'll at least need a mediatory Service for that.

醉生梦死 2024-09-14 11:06:57

使其静态。
为什么要用定时器来计时?使用currentTimeMillis()会更好。

Make it static.
Why you use timer to count time? Will be better to use currentTimeMillis ().

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