android提供5中数据存储方式

  •   数据存储之共享参数     
  •   内部存储
  •   扩展存储
  •   数据库存储
  •   网络存储
 而共享存储提供一种可以让用户存储保存一些持久化键值对在文件中,以供其他应用对这些共享参数进行调用。共享存储的数据类型包括:boolean/float/int/long/String,接下来是我在学习中的示例代码,实例代码中,通过junit进行单元测试,所以需要加入单元测试需要添加的测试包,以及添加单元测试的约束。
  AndroidManifest.xml
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.example.android_data_storage_share"
 4     android:versionCode="1"
 5     android:versionName="1.0" >
 6 
 7     <uses-sdk
 8         android:minSdkVersion="8"
 9         android:targetSdkVersion="18" />
10     <!-- 添加单元测试的约束 -->
11     <instrumentation
12         android:name="android.test.InstrumentationTestRunner"
13         android:targetPackage="com.example.android_data_storage_share" >
14     </instrumentation>
15 
16     <application
17         android:allowBackup="true"
18         android:icon="@drawable/ic_launcher"
19         android:label="@string/app_name"
20         android:theme="@style/AppTheme" >
21 
22         <!-- 单元测试需要添加单元测试包user-library -->
23         <uses-library android:name="android.test.runner" />
24 
25         <activity
26             android:name="com.example.android_data_storage_share.MainActivity"
27             android:label="@string/app_name" >
28             <intent-filter>
29                 <action android:name="android.intent.action.MAIN" />
30 
31                 <category android:name="android.intent.category.LAUNCHER" />
32             </intent-filter>
33         </activity>
34     </application>
35 
36 </manifest>
资源清单文件

相关文章: