Android的定制共享preferences实施坚持到数据库? [英] Android custom SharedPreferences implementation to persist to database?

查看:122
本文介绍了Android的定制共享preferences实施坚持到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用共享preferences 界面的自定义实现持久化应用程序的preferences到数据库中(而不是默认的XML) 。

I am attempting to use a custom implementation of the SharedPreferences interface to persist an application's preferences to a database (instead of the default XML).

为什么呢?我想使用的便利性 preferenceActivity 来构建用户界面,但这个程序将在多个设备,以使preferences用户设定需要使用坚持跨设备。

Why? I'd like to use the convenience of PreferenceActivity to construct the UI but this app will be used on multiple devices so the preferences a user sets need to persist across devices.

所以..我已经得到了实施而编写的,但无法弄清楚如何在特定的共享preference以 preferenceActivity 相关联。我知道,使用 getShared preferences(),但我怎么能覆盖吗?我可以注册我的共享preferences 不知何故?我没有看到在API中什么做到这一点。

So.. I've got the implementation written, but can't figure out how to associate a particular SharedPreference with a PreferenceActivity. I know that uses getSharedPreferences(), but how can I override that? Can i register my SharedPreferences somehow? I did not see anything in the API to do this.

或者......如果我要对此都错了,请让我知道。谢谢你。

Or ... if I'm going about this all wrong please let me know. Thanks.

推荐答案

我一直前一段时间调查这个问题。出于不同的原因,但。

I've been investigating this question some time ago. For a different reason though.

我发现的是, preferenceActivity 高度加上 preferenceManager ,它使用 preferenceManager.getDefaultShared preferences()内心深处获得共享preference 实例。而且也没有办法要么替代定制 preferenceManager 内的共享preference 实例 prefernceActivity

What I found is that PreferenceActivity is highly coupled with PreferenceManager and it uses PreferenceManager.getDefaultSharedPreferences() deep inside to get SharedPreference instance. And there is no way to either substitute custom PreferenceManager or SharedPreference instance inside PrefernceActivity.

我发现,preference框架是僵化的,它是十分困难的延长或更改默认行为,有时甚至它是不可能的。但我的猜测是,这本框架的设计人员易用性作为自己的首要任务,而不是扩展性和灵活性。这是可以理解的。

I found that Preference framework is inflexible and it's quite hard to extend or change default behaviors, and sometimes its even impossible. But my guess is that designers of this this framework had "ease of use" as their top priority, not extendability and flexibility. Which is understandable.

这篇关于Android的定制共享preferences实施坚持到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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