Android的 - 如何更新插件常常但只有当它是可见的? [英] Android - how update widget often but only when it is visible?

查看:168
本文介绍了Android的 - 如何更新插件常常但只有当它是可见的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建控件,它需要更新其内容的每分钟(它显示了与时间相关的数据)。

I'm going to create widget which needs to update its content every minute (it shows time-related data).

然而,也没有必要更新插件如果它当前不可见的,这意味着:

However, there is no need to update widget if it is currently invisible, which means:

  • 在关闭屏幕
  • 在另一个应用程序正在运行
  • 部件放置在另一个(隐形)主屏幕标签

什么是更新唯一可见的部件每分钟最好的办法 - 不起床设备,也没有做不必要的计算?之后小部件变为可见,更新前小的滞后是可以接受的。

What is the best way to update only visible widget every minute - without waking up device nor doing unnecessary computations? After widget becomes visible, small lag before update is acceptable.

推荐答案

要保持不能更新,当屏幕关闭时,使用的 AlarmManager 安排循环闹铃,不唤醒了电话。

To keep from updating when the screen is off, use the AlarmManager to schedule a recurring alarm that doesn't wakeup the phone.

你有你的问题的另外两个要点不可能的。有没有办法来检测,如果你的小部件是一个主屏幕是当前不可见的,并且没有办法确定一个应用程序正在运行的是隐藏在主屏幕上。我已经申请了票上 http://b.android.com 要求这一功能被加入到Android。如果你觉得自己主演的,它会帮助它获得优先权:<一href="http://$c$c.google.com/p/android/issues/detail?id=5529&q=reporter:mark.r.baird&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars">http://$c$c.google.com/p/android/issues/detail?id=5529&q=reporter:mark.r.baird&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

The other two bullet points you have in your question aren't possible. There is no way to detect if your widget is on a home screen that isn't currently visible, and there is no way to determine if an app is running that is hiding the home screen. I have filed a ticket on http://b.android.com requesting this functionality be added to Android. If you feel like starring it, it will help it gain priority: http://code.google.com/p/android/issues/detail?id=5529&q=reporter:mark.r.baird&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

这篇关于Android的 - 如何更新插件常常但只有当它是可见的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆