Android 小部件刷新 [英] Android Widget Refresh

查看:45
本文介绍了Android 小部件刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个小部件,但在刷新它时遇到了问题.我得到最初的 onUpdate ,如果我把它搁置了很长时间.

I have implemented a widget but have problems refreshing it. I get the initial onUpdate , and again if I leave it for ages.

但是,我希望主应用程序中的更改自动反映在小部件上.我如何让它刷新?有没有办法从我的活动中调用小部件(我只是做一个静态例程),或者有没有办法在每次手机返回主屏幕时强制调用我的onUpdate"?

However I want changes in my main application to be automatically reflected on the widget. How do I get that to refresh ? Is there a way of calling the widget from my Activity (do I just do a static routine) or is there a way I can force my "onUpdate" to be called each time the phone returns back to the home screen ?

推荐答案

您是否使用服务来实现您的小部件来更新 RemoteViews?如果是这样,您可以使用 Intent 启动该服务,并且小部件将更新.

Did you implement your widget using a service to update the RemoteViews? If so you can kick off that service with an Intent and the widget will update.

Intent widgetUpdateIntent = new Intent(context, MyClassName.UpdateService.class);
context.startService(widgetUpdateIntent );

这篇关于Android 小部件刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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