在android程序中,如何知道桌面是否可见?是否有像Intent.ACTION_DESKTOP_VISIBLE和INVISIBLE这样的过滤动作?
想象一下,您正在开发一个带有后台服务的小部件,它会快速消耗电池,所以您不希望它一直运行:当屏幕关闭时,停止它。当屏幕打开时启用它。但这还不够,当有前台活动正在运行时(您看不到该小部件,因此您不需要它。停止它)。当我们回到桌面时重新启用它。
有解决办法吗?帮助!
Imagine you are working on a widget with a background service , and it eat battery fast, So you don't want it to run all the time: when the sceen off, stop it. When the screen on enable it. But that is not enough, when there is a foreground activity running( you cannot see the widget, so you don't need it.stop it ). And renable it when we back to the desktop.
Is there a solution? Help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,没有任何意图广播告诉您桌面何时或何时不可见。小部件只应该为您的应用程序提供轻量级窗口 - 解决方案是减少小部件的电池使用量。
如果您将
AlarmManager
与非_WAKEUP
闹钟类型一起使用来更新您的小部件并在 XML 中指定更新时间为 0,则您的小部件只会在手机醒了。There aren't any Intents broadcast AFAIK that tell you when or when not the desktop is not visible. Widgets are only supposed to lightweight windows onto your application - the solution is to reduce the battery usage of your widget.
If you use
AlarmManager
together with a non_WAKEUP
alarm type to update your widget and specify an update time of 0 in your XML, then your widget will only be updated while the phone is awake.