Android的性能:共享preferences成本 [英] Android performance: cost of SharedPreferences

查看:134
本文介绍了Android的性能:共享preferences成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序启动,我填充值的容器类从我的碎片preFS。当时的想法是处理共享preferences和preferenceManager一次,因为我猜他们是沉重的。结果下面是一个示例:

When my app starts, I populate a container class with values from my shard prefs. The idea was to handle the SharedPreferences and PreferenceManager once since I'm guessing they're heavy.
Here's a sample:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(cont); 
StorageClass.lifespan = Integer.parseInt( prefs.getString("lifespan", "8") );
StorageClass.hiRate = Integer.parseInt( prefs.getString("hiRate", "71") );
//and on and on for all preferences 

其他活动则要求这些值。结果
但正如我的应用程序的增长,主存储器变得紧张。

Other activities then request these values.
But as my app grows, main memory is becoming tight.

它会更好,以在每次请求做出共享preferences的实例,并得到他们想要的价值?

Would it be better to have every requester make an instance of SharedPreferences and get the value they want?

感谢

推荐答案

每次请求的同名preferences时间返回相同的共享preferences对象。如果不是这种情况,就必须处理多个共享preference对象保持其状态同步时,它是由其中的一个变化框架里面有很多复杂的code的。

The same SharedPreferences object is returned each time you request the preferences of the same name. If that wasn't the case, there would need to be a lot of complicated code inside the framework to deal with multiple SharedPreference objects keeping their state in sync when it is changed by one of them.

(这是一种-背后称其为共享preferences的想法。)

(This is kind-of the idea behind calling it "shared" preferences.)

这篇关于Android的性能:共享preferences成本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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