欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android使用SharedPreferences存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)方法

 更新時(shí)間:2016年06月23日 11:43:33   作者:hbiao68  
這篇文章主要介紹了Android使用SharedPreferences存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)方法,可實(shí)現(xiàn)針對(duì)短信的臨時(shí)保存功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了Android使用SharedPreferences存儲(chǔ)數(shù)據(jù)的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

編輯短信的時(shí)候,突然接收到電話,通過(guò)這種方式可以保存之前已經(jīng)編輯好的短信內(nèi)容

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  // 用只讀模式打開(kāi)/data/data/包名/shared_prefs/huangbiao.xml文件
  SharedPreferences sharedPreferences = getSharedPreferences("huangbiao", MODE_WORLD_READABLE);
  //得到鍵為key的值,如果沒(méi)有temp值為default,如果存在temp為key的值
  String temp = sharedPreferences.getString("key", "default");
  Toast.makeText(this, temp, Toast.LENGTH_SHORT).show();
}
@Override
protected void onStop() {
  super.onStop();
  //打開(kāi)或新建huangbiao.xml,并且編輯里面的內(nèi)容
  //SharedPreferences類(lèi)是為了得到里面的數(shù)據(jù),Editor類(lèi)是為了保存里面的數(shù)據(jù)
  SharedPreferences.Editor edit = getSharedPreferences("huangbiao", Context.MODE_WORLD_READABLE).edit();
  //向huangbiao.xml文件中添加鍵為key值為value的xml數(shù)據(jù)
  edit.putString("key", "value");
  edit.commit();
}

huangbiao.xml文件中的數(shù)據(jù)
文件的路徑如下:/data/data/包名/shared_prefs/huangbiao.xml

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
  <string name="huangbiao">biaobiao</string>
  <string name="abc">abc</string>
</map>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Android文件操作技巧匯總》、《Android編程開(kāi)發(fā)之SD卡操作方法匯總》、《Android開(kāi)發(fā)入門(mén)與進(jìn)階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論