Android 屏幕锁/车载充电器正在杀死我的线程

发布于 2024-09-18 07:35:02 字数 369 浏览 3 评论 0原文

我有一个非常棘手的问题无法解决。我有一个应用程序,可以远程将其置于飞行模式以节省电量。我有一个正在运行的线程,它获取省电消息,删除所有其他线程的回调,将手机置于飞行模式,并在唤醒手机之前等待指定的分钟数。

当手机插入我的笔记本电脑(启用 USB 调试等)时,此功能就可以了。手机进入飞行模式,屏幕锁定,然后在特定的分钟数后,应用程序“唤醒”并继续正常运行。

当手机插入车载充电器时,手机会进入飞行模式,但线程永远不会唤醒手机。仅当屏幕也设置为超时时才会出现此问题......当我将屏幕设置为“永不超时”并将手机插入车载充电器时,应用程序唤醒得很好。

电源和屏幕超时的某种组合似乎在系统级别杀死了我的省电线程。我知道这篇文章非常适合我的应用程序,但是以前有人遇到过类似的问题吗?

I have a very tough problem I can't solve. I have an app which I can put into airplane mode remotely to save power. I have a thread running which gets the power-save message, removes callbacks for all other threads, puts the phone into airplane mode, and waits a specified number of minutes before waking the phone back up.

When the phone is plugged into my laptop (USB debugging enabled, etc) then this functionality is fine. The phone goes into airplane mode, the screen locks, and then after a specific number of minutes the app "wakes up" and continues as normal.

When the phone is plugged into a car charger, the phone phone goes into airplane mode, but the thread never wakes up the phone. This problem only occurs when the screen is also set to timeout...when I set the screen to "never timeout" and have the phone plugged into a car charger, the app wakes up just fine.

It appears that some combination of power source and the screen timing out kills my power-save thread at a system level. I know this post is very specific to my application, but has anyone encountered a problem similar to this before?

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

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

发布评论

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

评论(1

白馒头 2024-09-25 07:35:02

如果你想等待n分钟,你需要使用闹钟,而不是线程。当您的应用程序不在前台时,您永远不能假设线程保持活动状态。查看 http://developer.android.com/reference/android/app/ AlarmManager.html

If you want to wait n number of minutes, you need to use an alarm, not a thread. You can never assume that a thread remains active while your application is not in the foreground. Check out http://developer.android.com/reference/android/app/AlarmManager.html.

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