/shared_prefs目錄下。SharedPreferences對象本身只能獲取數據而不支持存儲和修改,存儲修改是通過Editor對象實現。。。' />

伊人伊人伊人-亚洲伊人久久一次-天堂伊人网-伊人国产在线观看-在线播放精品-在线播放国产一区

1、SharedPreferences的簡單介紹

        應用程序在運行的時候,可能會隨著用戶的使用而保持該用戶的配置信息,如上次播放時的eq設置,音量設置,上網的cookies信息等等,這些小量 的信息可以通過SharedPreferences來保持,通過SharedPreferences保持的數據為一個XML文件,位于應用程序的私有文件夾。

2、具體操作方法

獲取SharedPreferences,可以通過以下方法獲取

public SharedPreferences getSharedPreferences (String name, int mode)

Since: API Level 1

Retrieve and hold the contents of the preferences file 'name', returning a SharedPreferences through which you can retrieve and modify its values. Only one instance of the SharedPreferences object is returned to any callers for the same name, meaning they will see each other's edits as soon as they are made.

Parameters
name Desired preferences file. If a preferences file by this name does not exist, it will be created when you retrieve an editor (SharedPreferences.edit()) and then commit changes (Editor.commit()).
mode Operating mode. Use 0 or MODE_PRIVATE for the default operation,MODE_WORLD_READABLE andMODE_WORLD_WRITEABLE to control permissions. The bitMODE_MULTI_PROCESS can also be used if multiple processes are mutating the same SharedPreferences file.MODE_MULTI_PROCESS is always on in apps targetting Gingerbread (Android 2.3) and below, and off by default in later versions.
Returns
  • Returns the single SharedPreferences instance that can be used to retrieve and modify the preference values.

 

參數簡述:

Name————獲得SharedPreferences之后,將會在應用程序的私有文件夾中保存著一個XML文件,第一個參數name就是這個文件名字。

Mode————XML文件的保存模式,默認為0,也就是MODE_PRIVATE

 

3、簡單的demo

通過service的一個音樂播放例子,“播放”與“暫停”兩個按鈕

暫停之后,保持播放進度到SharedPreferences里面,然后再次播放的話,讀取進度值進行音樂播放。

穩定

產品高可用性高并發

貼心

項目群及時溝通

專業

產品經理1v1支持

快速

MVP模式小步快跑

承諾

我們選擇聲譽

堅持

10年專注高端品質開發
  • 返回頂部
主站蜘蛛池模板: 清原| 潼南县| 元谋县| 定西市| 鄂州市| 合肥市| 望谟县| 鄯善县| 筠连县| 长宁区| 浑源县| 福贡县| 鸡泽县| 丰都县| 昌宁县| 华安县| 昌都县| 青铜峡市| 东台市| 会昌县| 延安市| 嘉黎县| 措美县| 资兴市| 恩施市| 临夏县| 新邵县| 黄石市| 农安县| 英吉沙县| 什邡市| 兰坪| 鄢陵县| 榆林市| 黄浦区| 喀喇沁旗| 金寨县| 洱源县| 双柏县| 赣州市| 洪泽县|