gpt4 book ai didi

java - Android 暂停并完成

转载 作者:行者123 更新时间:2023-12-01 14:39:15 26 4
gpt4 key购买 nike

嗨,我开始研究 Android 开发,但找不到关于贪睡功能的好教程。这是我的问题:

我有一个简单的闹钟,我想实现贪睡功能。我有一个 AlarmActivity 传递启动 AlarmAlertActivity 的 Intent 。但是,当按下贪睡按钮时,我想在 AlarmAlertActivity 上调用 finish 。我使用计时器在 AlarmAlertActivity 中编写了贪睡方法。但是,当 AlarmAlertActivity 类完成时,计时器不再运行。我真的不想再做一次返回 AlarmActivity 的 Intent ,因为可能会有多次小睡。如有任何帮助,我们将不胜感激!

最佳答案

您希望将此功能实现为 Service ,而不是作为 Activity 的一部分。来自文档:

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.

您可以设计 AlarmAlertActivity 来与服务交互(如有必要,启动它)。然后,当暂停时间结束时,该服务可以广播一条消息。

很难提供任何具体建议,因为您没有提供有关您正在做的事情的任何详细信息。然而,this thread上的代码可能会提供一些指导。

关于java - Android 暂停并完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16153515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com