操作步骤: |
1 .获得SharedPreferences对象 |
2 .调用SharedPreferences对象的edit()方法来获取一个SharedPreferences.Editor对象 |
3 .向SharedPreferences.Editor对象中添加数据,用putString()等方法 |
4 .调用commit()方法将数据进行提交 |
5 .注意,不用临时变量保存editor,就不能正常保存数据 |
SharedPreferences.Editor editor = getSharedPreferences( "UPDATE_DATA_TIME" , Context.MODE_PRIVATE).edit(); |
editor.putString( "data" , "你好" ); |
//保存数据 |
SharedPreferences sp = getSharedPreferences( "UPDATE_DATA_TIME" , Context.MODE_PRIVATE); |
SharedPreferences.Editor editor = sp.edit(); |
editor.putString( "data" , "你好" ); |
editor.commit(); |
//取出数据 |
String name=sp.getString( "data" ); |
Log.v( "测试数据" ,name); |
} |
by: 发表于:2017-09-26 11:43:43 顶(0) | 踩(0) 回复
??
回复评论