不同进程中的 OnPreferenceChangeListener - 共享偏好数据
所以我的问题如下:我有两个服务在不同的进程中运行,并且希望保持这种方式。一种是将数据从数据库总线传输到绑定应用程序,第二种是通过套接字轮询传入数据。我觉得将这些保留在独立的过程中会更好。问题是我希望在两个服务之间有一个共享的首选项,并希望实现 OnSharedPreferenceChangeListener 来更新轮询和总线数据所需的设置。我无法在服务中实现 OnSharedPreferenceChangeListener 因为它们在不同的进程上运行。我可以在 PreferenceActivity 上实现此功能,但如何与服务通信以立即更新?我不想使用 AIDL 并担心绑定。可以创建广播接收器并发送意图,但如果设置菜单增加,这些似乎是一项艰巨的工作。还有其他好主意吗?
So my problem is as follows: I have 2 services running in different processes and would like to keep it this way. One is busing data from databases to bound applications and the second is polling for incoming data through sockets. I feel keeping these in independent process would be better. The problem is that I would like to have a shared preferences between the two services and would like to implement OnSharedPreferenceChangeListener to update setting needed for polling and busing data. I can't implement OnSharedPreferenceChangeListener in the services since they run on different processes. I could implement this on the PreferenceActivity but how do I communicate to the services for immediate update? I do not want to use AIDL and worry about binding. There is the possibility of creating broadcast receivers and sending out intents but these seems like a big work around if the settings menu grows. Any other great ideas out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这就是您的答案...
对于此示例的首选项,让我们采用 3 个类 - 2 个服务服务 A 和 B(href A,B)和设置(preferenceActivity)
将这两个服务初始化为
共享首选项部分。
我在我的一个应用程序中实现了这个系统...并部署了...所以摆弄这些基础知识并让我知道它是如何进行的...
Rajesh...
all right here is your answer...
for the preference of this example lets take 3 classes - 2 services service A and B (href A,B) and Settings(preferenceActivity)
initialize the two services as
Shared preference Part.
I have this system implemented in one of my applicaiton... and deployed... so fiddle around these basics and let me know how it is goes...
Rajesh...
我创建了一个基于ContentProvider的简单SharedPreferences,它可以跨进程使用,你可以从我的bitbucket中找到它们 https://bitbucket.org/ABitNo/zi/src/783b6b451ba1/src/me/abitno/zi/provider/preference
I've created a simple SharedPreferences based on ContentProvider, which can be used accross processes, you can find them from my bitbucket https://bitbucket.org/ABitNo/zi/src/783b6b451ba1/src/me/abitno/zi/provider/preference