Android - 通过AIDL服务更新TextView字符串

发布于 2024-09-14 18:53:56 字数 313 浏览 4 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2024-09-21 18:53:57

但是,显然 Android 无法以编程方式更新字符串资源。

正确的。

我看到的唯一替代解决方案
将使用 SharedPreference。我
担心访问数据库
每次刷新该值时。

共享首选项不存储在数据库中。它们存储在 XML 文件中。

任何人都可以与我分享一些选项吗?

让服务在更改数据时广播Intent。或者,让服务调用选项卡提供的侦听器对象。可能还有六个其他选项,但这两个选项应该可以帮助您开始这条道路。

However, apparently Android can not update String resources programatically.

Correct.

The only alternative solution I see
would be using SharedPreference. I
have concerns accessing a Database
everytime the value is refreshed.

Shared preferences are not stored in a database. They are stored in an XML file.

Can anyone please share some options with me.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文