持续通知会让我的应用程序保持活力吗?

发布于 2024-10-19 00:27:42 字数 477 浏览 3 评论 0原文

我正在开发一个秒表风格的应用程序,它可能一次运行几个小时。在调试时,我在手机上运行了一夜,结果发现该应用程序在夜间的某个时候发布,并发现早上它并没有像我希望的那样运行。

为了提高效率,我跟踪秒表的启动时间,并且仅在应用程序可见时更新显示。 onPause() 我的计时器线程(更新 UI 的线程)暂停,而 onResume() 我恢复该线程。这意味着当我的应用程序处于后台时,没有任何反应,并且在长时间打开时会被标记为关闭。

为了让我的应用程序变得更加持久,我可以在秒表滴答作响时发出持续通知吗?

有些人可能会说,如果我的应用程序没有执行任何操作,那么它应该关闭。尽管看起来确实如此,但它本质上是在记录时间。即使这意味着它没有主动执行任何操作,它也会等待用户停止记录时间。我不希望持续的通知只是让我的应用程序保持活动状态,而且还提醒用户他们正在监控它的时间。

如果持续通知不能让我的应用程序持久存在,我有哪些轻量级替代方案?

I'm working on a stopwatch style app that might be running for hours at a time. While debugging, I ran it overnight on my phone only to find that the app was released sometime during the night, and found in the morning it was not running like I'd hoped it would be.

In order to be more efficient, I keep track of what time the stopwatch was started and I only update the display while the app is visible. onPause() my timer thread (the one updating my UI) suspends and onResume() I resume the thread. This means while my app is backgrounded, nothing is happening and it gets flagged to be closed when left on for a long period of time.

In hopes of my app becoming more persistent, can I just put up an Ongoing Notification while the stopwatch is ticking?

Some may say that if my app isn't doing anything then it should close. As true as that appears to be, it's inherently keeping track of time. Even if that means it's not actively doing anything, it's waiting for the user to stop keeping track of time. I do not want the ongoing notification to simply keep my app alive, but also to remind the user that they're monitoring time with it.

If an Ongoing Notification won't keep my app persistent, what light-weight alternatives do I have?

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

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

发布评论

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

评论(1

把时间冻结 2024-10-26 00:27:42

为什么需要保持应用程序运行?难道你不能只存储运行/暂停/停止状态和开始时间,然后在应用程序启动时重新计算经过的时间吗?

Why do you need to keep the app running? Can't you just store running/paused/stopped state, and the start time, then recalculate the elapsed time when the app's started?

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