Android的永久记忆 [英] android permanent memory

查看:148
本文介绍了Android的永久记忆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序不同的操作deppending主叫方和一些predefined值。
当呼叫开始响我需要尽可能快地读取来自数据库的preferences并显示它们。
我想有静态变量的广播接收器,我也试图让他们的服务,但它只是似乎死和适度宽松的所有的值。
如果我从databade读取它们再次花费太长时间来显示信息。
那么,有没有办法告诉Android的尊重记忆的一部分,所以我可以坚持的信息?

My app does different actions deppending on the caller and some predefined values. When a call is starting to ring I need to be as fast as possible to read those preferences from the data base and display them. I tried to have static variables in the BroadcastReceiver, I also tried to have them in a Service but it just seems to die and loose all the values. If I read them from the databade again it takes too long to display the information. So, is there any way to tell Android to respect part of the memory so I can persist the information?

感谢

编辑:?从共享preferences读取任何速度比从一个小型的数据库中读取

EDITED: Is reading from SharedPreferences any faster than reading from a small database?

推荐答案

使用共享preferences,它们就像你应用程序的私有部分,将节省你的价值观永久,直到用户重新安装(透明数据)的应用。共享preferences工作原理是这样

use SharedPreferences, they are like a private part of you application that will save your values permanently, untill user reinstall (clear data) application. Shared Preferences works like this

// save string in sharedPreferences
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putString("some_key", string); // here string is the value you want to save
                    editor.commit();                    

// restore string in sharedPreferences 
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
string = settings.getString("some_key", "");

显然,你可以保存,而不是字符串INT布尔型等等

Obviously you can save int boolean etc instead of string

这篇关于Android的永久记忆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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