Android - 通过AIDL服务更新TextView字符串
我有一个使用 TabHost 的应用程序。 几个选项卡共享一个公共 HUD。 我正在使用一项服务,通过在准备好时调用 AIDL 函数来定期更新这些值。
然而,由于几个选项卡使用相同的 HUD,我想将该部分抽象出来。
我考虑过让 HUD.xml 使用 String 资源作为它的值,然后抽象类可以更新 String 资源。但是,显然 Android 无法以编程方式更新 String 资源。
我看到的唯一替代解决方案是使用 SharedPreference。 我担心每次刷新值时都会访问数据库。
任何人都可以与我分享一些选择吗?
谢谢
I have an app that uses a TabHost.
Several of the Tabs share a common HUD.
I am using a service to periodically update those values by calling an AIDL function when ready.
However, since several of the Tabs are using the same HUD I would like to abstract that part out.
I thought about having the HUD.xml use a String resource as it's value and then the abstracted class can update the String resource. However, apparently Android can not update String resources programatically.
The only alternative solution I see would be using SharedPreference.
I have concerns accessing a Database everytime the value is refreshed.
Can anyone please share some options with me.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的。
共享首选项不存储在数据库中。它们存储在 XML 文件中。
让服务在更改数据时广播
Intent
。或者,让服务调用选项卡提供的侦听器对象。可能还有六个其他选项,但这两个选项应该可以帮助您开始这条道路。Correct.
Shared preferences are not stored in a database. They are stored in an XML file.
Have the service broadcast an
Intent
when it changes the data. Or, have the service call listener objects supplied by the tabs. There's probably a half-dozen other options as well, but those two should get you started down the path.