仅在设备处于打开状态且主屏幕上可见窗口小部件时更新窗口小部件 [英] Updating a widget only when device is on AND widget is visible on home screen

查看:51
本文介绍了仅在设备处于打开状态且主屏幕上可见窗口小部件时更新窗口小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解的有关Widget的官方文档,我有些困惑.

As far as I understood the official documentation about Widgets I am a little bit confused.

标准"方式是定义BroadcastReceiver并以毫秒为单位定义更新频率-这种方式允许最少30分钟的更新间隔以节省电池电量.听起来很合理.

The "standard" way would be to define a BroadcastReceiver and define the update frequency in milliseconds - this way allows a minimum update interval of 30 minutes to save battery power. Sounds reasonable.

我发现阅读Google文档的手动"方式是使用AlarmManager自己处理小部件的更新.使用此方法,可能有较高的更新间隔(当然不建议这样做!),并且有可能使用在睡眠时不会唤醒设备的警报类型. (我认为在事件因设备由于其他某种原因唤醒后立即触发,便会立即发送意图.)

The "manual" way I found reading the Google documentation would be to handle the update of widgets yourself using the AlarmManager. Using this method higher update intervals are possible (though of course discouraged!) and it would be possible to use alarm types that do not wake up the device when asleep. (I assume the intent is sent any time after the event should trigger as soon as the device wakes up for some other reason - is that right??)

现在,我对以下想法感到困惑:小部件位于主屏幕上.或者至少这是它们最常见的地方. Android在主屏幕上提供了许多页面(标准为5或7),因此即使用户将其放置在窗口小部件中,它也可能不可见!

Now, I get confused by the following thought: widgets reside on home screens. Or at least that's the most common place they will be found. Android offers many pages (standard is 5 or 7) on home screens, so a Widget, even though placed there by the user, might not even be visible!

只要窗口小部件显示的信息只是非常简单的文本(如当前时间!),就可以在需要时立即计算或导出,我不希望任何不可见的更新频率甚至设备唤醒意图!
但是,只要设备处于打开状态或更具体:只要屏幕处于打开状态且窗口小部件可见,我就需要很多更新事件!就像时钟一样,显示秒数需要每秒重绘一次!

As long as the information a widget displays is just a very simple text (like the current time!) that could be calculated or derived without any delay whenever needed, I do not want any update frequency or even device wake-up intents when it is not visible!
But as long as the device is on, or more specific: as long as the screen is on AND the widget is visible, I want a lot of update events! Like a clock displaying the seconds needs an intent to redraw every second!

那怎么实现?如何实现"Android模拟时钟"?方法A(标准")和方法B(手动")都没有给我带来很高的更新频率,但前提是设备打开且我的窗口小部件可见.

How can that be realized? How is the "Android analog clock" realized? Neither method A ("standard") nor B ("manual") give my high update frequency but only as long as the device is on and my widget is visible.

有人可以给我一个提示吗?

Can anybody give me a hint???

推荐答案

我认为在事件应在设备由于某种其他原因唤醒后立即触发后,便会立即发送意图.

I assume the intent is sent any time after the event should trigger as soon as the device wakes up for some other reason - is that right??

是的

当它不可见时,我不希望有任何更新频率甚至设备唤醒意图!

I do not want any update frequency or even device wake-up intents when it is not visible!

但是在很多情况下,您的用户都可以.您所做的任何值得在更新中执行的操作都可能需要花费几秒钟的时间.用户不会坐在那里等待几秒钟.因此,应用程序小部件更新模型表示您可以不断更新应用程序小部件,因此当用户查看应用程序小部件时,他们会立即拥有更新的数据.

But your users do, in many cases. Anything you do that is worth doing in the update may take some number of seconds. The user is not going to sit there waiting some number of seconds. Hence, the app widget update model says that you keep the app widget updated constantly, so when the user goes looking at the app widget, they have the updated data right away.

但是只要打开设备或更具体:只要屏幕打开且小部件可见,我就需要很多更新事件!就像时钟一样,显示秒数需要每秒重绘一次!

But as long as the device is on, or more specific: as long as the screen is on AND the widget is visible, I want a lot of update events! Like a clock displaying the seconds needs an intent to redraw every second!

编写您自己的主屏幕应用程序.

Write your own home screen app.

"Android模拟时钟"如何实现?

How is the "Android analog clock" realized?

这是主屏幕应用程序的功能.

It is a feature of the home screen app.

这篇关于仅在设备处于打开状态且主屏幕上可见窗口小部件时更新窗口小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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