国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

SharedPreferences共享

2019-11-09 15:40:52
字體:
供稿:網(wǎng)友
Context.getSharedPReferences(String, int mode)Context.MODE_PRIVATE: 指定該SharedPreferences的數(shù)據(jù)只能被本應(yīng)用程序讀、寫Context.MODE_APPEND:新內(nèi)容追加到原內(nèi)容后Context.MODE_WORLD_READABLE:  指定 SharedPreferences數(shù)據(jù)能被其他應(yīng)用程序讀,但是不支持寫---過時Context.MODE_WORLD_WRITEABLE: 指定 SharedPreferences數(shù)據(jù)能被其他應(yīng)用程序讀、寫會覆蓋原數(shù)據(jù)---過時

可以使用"+"連接這些權(quán)限

使用SharedPreferences的步驟1、獲取SharedPreferences對象2、調(diào)用edit()方法獲取SharedPreferences.Editor3、通過SharedPreferences.Editor接口提供的put()方法對SharedPreferences進(jìn)行更新4、調(diào)用SharedPreferences.Editor的commit()方法,將更新提交到SharedPreferences中

內(nèi)部存儲FileOutputStream Context.openFileOutput (String filename, int mode)Context.MODE_APPENDContext.MODE_PRIVATEContext.MODE_WORLD_READABLE--過時Context.MODE_WORLD_WRITEABLE--過時FileInputStream Context.openFileInput (String filename)String[] Context.fileList()Context.deleteFile(String filename)

實(shí)現(xiàn)SharedPreferences存儲的步驟如下:

  一、根據(jù)Context獲取SharedPreferences對象

  二、利用edit()方法獲取Editor對象。

  三、通過Editor對象存儲key-value鍵值對數(shù)據(jù)。

  四、通過commit()方法提交數(shù)據(jù)。

@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.zhuce);    initView();}private void initView() {    qyhm=(EditText)findViewById(R.id.qyhm);    qmm=(EditText)findViewById(R.id.qmm);    zzc=(Button)findViewById(R.id.zzc);}public void onClick(View v){    SharedPreferences sp=getSharedPreferences("Count", Context.MODE_APPEND+Context.MODE_PRIVATE);    SharedPreferences.Editor ed=sp.edit();    String str1=qyhm.getText().toString();    String str2=qmm.getText().toString();    ed.putString("Count",str1);    ed.putString("Count2",str2);    ed.commit();    finish();}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 北碚区| 临高县| 鹿泉市| 元氏县| 乌兰察布市| 梁山县| 桃源县| 家居| 清新县| 梓潼县| 德保县| 天水市| 丰都县| 米易县| 铜陵市| 饶平县| 吉木萨尔县| 晋中市| 贡山| 罗城| 迁西县| 鸡东县| 汉沽区| 阳西县| 开封县| 明光市| 离岛区| 曲靖市| 理塘县| 庄河市| 朝阳县| 桐乡市| 彰武县| 拜城县| 遂川县| 巴南区| 加查县| 丹巴县| 兴城市| 韩城市| 廊坊市|