谁动了我的代码

抽象即是空,空即是抽象。
posts(43) comments(24) trackbacks(0)
  • BlogJava
  • 联系
  • RSS 2.0 Feed 聚合
  • 管理

News

所有文章版权归我所有,转载请注明出处,谢谢!

常用链接

  • 我的随笔
  • 我的评论
  • 我的参与
  • 最新评论

留言簿

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类

  • Android开发(5)
  • C/C++(1)
  • DataBase(3)
  • Java(16)
  • JavaScript(14)
  • WEB前端(1)
  • 编程杂项(2)
  • 网络(1)

随笔档案

  • 2016年5月 (1)
  • 2011年2月 (1)
  • 2010年6月 (3)
  • 2010年5月 (1)
  • 2009年12月 (2)
  • 2009年11月 (1)
  • 2009年10月 (2)
  • 2009年6月 (2)
  • 2009年5月 (1)
  • 2009年4月 (2)
  • 2009年3月 (4)
  • 2009年2月 (1)
  • 2009年1月 (1)
  • 2008年12月 (1)
  • 2008年11月 (1)
  • 2008年10月 (4)
  • 2008年9月 (2)
  • 2008年5月 (5)
  • 2008年3月 (3)
  • 2007年12月 (2)
  • 2007年10月 (1)
  • 2007年9月 (2)
  • 2007年5月 (1)

搜索

  •  

最新评论

  • 1. re: Android之ImageView载入网络上的图片
  • 222222222222222222222
  • --2222222222222222222222222222
  • 2. re: Log4j自带Log Viewer的用法
  • 执行你的根本不行,乱错帖子就在这乱贴,tmd
  • --asdf
  • 3. re: Android之使用私有存储
  • getDir方法创建的文件,会有个app_前缀,请问这怎么去掉呢?
  • --就是宝宝
  • 4. re: Android通用事件造成的生命周期变化情况
  • 我相信以后Android将成为越来越多设备的OS,不光是手持上网设置,冰箱、洗衣机都有可能采用Android。
  • --淘宝网女装春装新款
  • 5. re: Android通用事件造成的生命周期变化情况
  • 不错
  • --歌瑞尔内衣

阅读排行榜

评论排行榜

View Post

Android之Shared Preferences

懒得再翻译,这段应该很好理解,直接将Dev Guide中复制过来。


The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

To get a SharedPreferences object for your application, use one of two methods:

  • getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.
  • getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.

To write values:

  1. Call edit() to get a SharedPreferences.Editor.
  2. Add values with methods such as putBoolean() and putString().
  3. Commit the new values with commit()

To read values, use SharedPreferences methods such as getBoolean() and getString().

Here is an example that saves a preference for silent keypress mode in a calculator:


 1public class Calc extends Activity {
 2    public static final String PREFS_NAME = "MyPrefsFile"
;
 3

 4
    @Override
 5    protected void onCreate(Bundle state)
{         
 6       super
.onCreate(state);
 7
       . . .
 8

 9       // Restore preferences

10       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
11       boolean silent = settings.getBoolean("silentMode", false
);
12
       setSilent(silent);
13    }

14
15
    @Override
16    protected void onStop()
{
17       super
.onStop();
18

19      //
 We need an Editor object to make preference changes.
20      // All objects are from android.context.Context

21      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
22      SharedPreferences.Editor editor =
 settings.edit();
23      editor.putBoolean("silentMode"
, mSilentMode);
24

25      // Commit the edits!

26      editor.commit();
27    }

28}

posted on 2010-06-07 17:18 Eric Song 阅读(422) 评论(0)  编辑  收藏 所属分类: Android开发

新用户注册  刷新评论列表  

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问   管理
相关文章:
  • Android通用事件造成的生命周期变化情况
  • Android之ImageView载入网络上的图片
  • Android之Shared Preferences
  • Android之使用私有存储
  • Android开发之调用系统彩信发送功能
 
 
Powered by:
BlogJava
Copyright © Eric Song