Android 屏幕锁/车载充电器正在杀死我的线程
我有一个非常棘手的问题无法解决。我有一个应用程序,可以远程将其置于飞行模式以节省电量。我有一个正在运行的线程,它获取省电消息,删除所有其他线程的回调,将手机置于飞行模式,并在唤醒手机之前等待指定的分钟数。
当手机插入我的笔记本电脑(启用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想等待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.