数据存储在开发中是使用最频繁的,在这里主要介绍Android平台中实现数据存储的5种方式,更加系统详细的介绍了5种存储的方法和异同。
第一种: 使用SharedPreferences存储数据
SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置比如窗口状态,一般在Activity中 重载窗口状态onSaveInstanceState保存一般使用SharedPreferences完成,它提供了Android平台常规的Long长 整形、Int整形、String字符串型的保存。
它是什么样的处理方式呢? SharedPreferences类似过去Windows系统上的ini配置文件,但是它分为多种权限,可以全局共享访问,android123提示最终是以xml方式来保存,整体效率来看不是特别的高,对于常规的轻量级而言比SQLite要好不少,如果真的存储量不大可以考虑自己定义文件格式。xml 处理时Dalvik会通过自带底层的本地XML Parser解析,比如XMLpull方式,这样对于内存资源占用比较好。
它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息。
其存储位置在/data/data/<包名>/shared_prefs目录下。
SharedPreferences对象本身只能获取数据而不支持存储和修改,存储修改是通过Editor对象实现。
实现SharedPreferences存储的步骤如下:
一、根据Context获取SharedPreferences对象
二、利用edit()方法获取Editor对象。
三、通过Editor对象存储key-value键值对数据。
四、通过commit()方法提交数据。
http://www.iteye.com/problems/125656
http://www.iteye.com/problems/125657
http://www.iteye.com/problems/125659
http://www.iteye.com/problems/125661
http://www.iteye.com/problems/125664
http://www.iteye.com/problems/125666
http://www.iteye.com/problems/125668
http://www.iteye.com/problems/125669
http://www.iteye.com/problems/125672
http://www.iteye.com/problems/125673
http://www.iteye.com/problems/125675
http://www.iteye.com/problems/125677
http://www.iteye.com/problems/125678
http://www.iteye.com/problems/125681
http://www.iteye.com/problems/125682
http://www.iteye.com/problems/125695
http://www.iteye.com/problems/125696
http://www.iteye.com/problems/125697
http://www.iteye.com/problems/125698
http://www.iteye.com/problems/125700
http://www.iteye.com/problems/125703
http://www.iteye.com/problems/125705
http://www.iteye.com/problems/125704
http://www.iteye.com/problems/125707
http://www.iteye.com/problems/125708
http://www.iteye.com/problems/125710
http://www.iteye.com/problems/125712
http://www.iteye.com/problems/125713
http://www.iteye.com/problems/125714
http://www.iteye.com/problems/125717
http://www.iteye.com/problems/125721
http://www.iteye.com/problems/125720
http://www.iteye.com/problems/125723
http://www.iteye.com/problems/125724
http://www.iteye.com/problems/125725
http://www.iteye.com/problems/125728
http://www.iteye.com/problems/125729
http://www.iteye.com/problems/125730
http://www.iteye.com/problems/125731
http://www.iteye.com/problems/125732
http://www.iteye.com/problems/125734
http://www.iteye.com/problems/125738
http://www.iteye.com/problems/125742
http://www.iteye.com/problems/125743
http://www.iteye.com/problems/125744
http://www.iteye.com/problems/125745
http://www.iteye.com/problems/125746
http://www.iteye.com/problems/125748
http://www.iteye.com/problems/125750
http://www.iteye.com/problems/125751
http://www.iteye.com/problems/125755
http://www.iteye.com/problems/125757
http://www.iteye.com/problems/125758
http://www.iteye.com/problems/125759
http://www.iteye.com/problems/125760
http://www.iteye.com/problems/125761
http://www.iteye.com/problems/125762
http://www.iteye.com/problems/125764
http://www.iteye.com/problems/125766
http://www.iteye.com/problems/125768
http://www.iteye.com/problems/125770
http://www.iteye.com/problems/125774
http://www.iteye.com/problems/125773
http://www.iteye.com/problems/125776
http://www.iteye.com/problems/125775
http://www.iteye.com/problems/125777
http://www.iteye.com/problems/125780
http://www.iteye.com/problems/125784
http://www.iteye.com/problems/125782
http://www.iteye.com/problems/125786
http://www.iteye.com/problems/125788
http://www.iteye.com/problems/125790
http://www.iteye.com/problems/125791
http://www.iteye.com/problems/125792
http://www.iteye.com/problems/125795
http://www.iteye.com/problems/125801
http://www.iteye.com/problems/125800
http://www.iteye.com/problems/125802
http://www.iteye.com/problems/125804
http://www.iteye.com/problems/125803
http://www.iteye.com/problems/125805
http://www.iteye.com/problems/125807
http://www.iteye.com/problems/125806
http://www.iteye.com/problems/125808
http://www.iteye.com/problems/125809
http://www.iteye.com/problems/125810
http://www.iteye.com/problems/125811
http://www.iteye.com/problems/125812
http://www.iteye.com/problems/125813
http://www.iteye.com/problems/125814
http://www.iteye.com/problems/125816
http://www.iteye.com/problems/125818
http://www.iteye.com/problems/125820
http://www.iteye.com/problems/125823
http://www.iteye.com/problems/125824
http://www.iteye.com/problems/125826
http://www.iteye.com/problems/125839
http://www.iteye.com/problems/125842
http://www.iteye.com/problems/125844
http://www.iteye.com/problems/125846
http://www.iteye.com/problems/125848
http://www.iteye.com/problems/125850
http://www.iteye.com/problems/125852
http://www.iteye.com/problems/125853
http://www.iteye.com/problems/125855
http://www.iteye.com/problems/125857
http://www.iteye.com/problems/125859
http://www.iteye.com/problems/125861
http://www.iteye.com/problems/125862
http://www.iteye.com/problems/125863
http://www.iteye.com/problems/125865
http://www.iteye.com/problems/125866
http://www.iteye.com/problems/125868
http://www.iteye.com/problems/125869
http://www.iteye.com/problems/125870
http://www.iteye.com/problems/125872
http://www.iteye.com/problems/125873
http://www.iteye.com/problems/125875
http://www.iteye.com/problems/125892
http://www.iteye.com/problems/125893
http://www.iteye.com/problems/125894
http://www.iteye.com/problems/125895
http://www.iteye.com/problems/125896
http://www.iteye.com/problems/125897
http://www.iteye.com/problems/125898
http://www.iteye.com/problems/125899
http://www.iteye.com/problems/125900
http://www.iteye.com/problems/125903
http://www.iteye.com/problems/125906
http://www.iteye.com/problems/125908
http://www.iteye.com/problems/125910
http://www.iteye.com/problems/125911
http://www.iteye.com/problems/125915
http://www.iteye.com/problems/125921
http://www.iteye.com/problems/125919
http://www.iteye.com/problems/125922
http://www.iteye.com/problems/125924
http://www.iteye.com/problems/125925
http://www.iteye.com/problems/125926
http://www.iteye.com/problems/125927
http://www.iteye.com/problems/125928
http://www.iteye.com/problems/125931
http://www.iteye.com/problems/125933
http://www.iteye.com/problems/125935
http://www.iteye.com/problems/125936
http://www.iteye.com/problems/125939
http://www.iteye.com/problems/125937
http://www.iteye.com/problems/125942
http://www.iteye.com/problems/125946
http://www.iteye.com/problems/125947
http://www.iteye.com/problems/125954
http://www.iteye.com/problems/125955
http://www.iteye.com/problems/125956
http://www.iteye.com/problems/125957
http://www.iteye.com/problems/125958
http://www.iteye.com/problems/125961
http://www.iteye.com/problems/125963
http://www.iteye.com/problems/125964
http://www.iteye.com/problems/125967
http://www.iteye.com/problems/125965
http://www.iteye.com/problems/125970
http://www.iteye.com/problems/125972
http://www.iteye.com/problems/125971
http://www.iteye.com/problems/125973
http://www.iteye.com/problems/125975
http://www.iteye.com/problems/125977
http://www.iteye.com/problems/125978
http://www.iteye.com/problems/125979
http://www.iteye.com/problems/125980
http://www.iteye.com/problems/125981
http://www.iteye.com/problems/125982
http://www.iteye.com/problems/125983
http://www.iteye.com/problems/125984
http://www.iteye.com/problems/125985
http://www.iteye.com/problems/125987
http://www.iteye.com/problems/125990
http://www.iteye.com/problems/125991
http://www.iteye.com/problems/125993
http://www.iteye.com/problems/125994
http://www.iteye.com/problems/125995
http://www.iteye.com/problems/125996
http://www.iteye.com/problems/125998
http://www.iteye.com/problems/126000
http://www.iteye.com/problems/126001
http://www.iteye.com/problems/126003
http://www.iteye.com/problems/126004
http://www.iteye.com/problems/126006
http://www.iteye.com/problems/126008
http://www.iteye.com/problems/126010
http://www.iteye.com/problems/126012
http://www.iteye.com/problems/126014
http://www.iteye.com/problems/126017
http://www.iteye.com/problems/126019
http://www.iteye.com/problems/126021
http://www.iteye.com/problems/126022
http://www.iteye.com/problems/126023
http://www.iteye.com/problems/126024
http://www.iteye.com/problems/126025
http://www.iteye.com/problems/126026
http://www.iteye.com/problems/126027
http://www.iteye.com/problems/126029
http://www.iteye.com/problems/126028
http://www.iteye.com/problems/126030
http://www.iteye.com/problems/126032
http://www.iteye.com/problems/126033
http://www.iteye.com/problems/126038
http://www.iteye.com/problems/126036
http://www.iteye.com/problems/126040
http://www.iteye.com/problems/126041
http://www.iteye.com/problems/126042
http://www.iteye.com/problems/126043
http://www.iteye.com/problems/126044
http://www.iteye.com/problems/126045
http://www.iteye.com/problems/126047
http://www.iteye.com/problems/126048
http://www.iteye.com/problems/126049
http://www.iteye.com/problems/126050
http://www.iteye.com/problems/126052
http://www.iteye.com/problems/126056
http://www.iteye.com/problems/126059
http://www.iteye.com/problems/126060
http://www.iteye.com/problems/126061
http://www.iteye.com/problems/126062
http://www.iteye.com/problems/126063
http://www.iteye.com/problems/126064
http://www.iteye.com/problems/126065
http://www.iteye.com/problems/126066
http://www.iteye.com/problems/126067
http://www.iteye.com/problems/126068
http://www.iteye.com/problems/126069
http://www.iteye.com/problems/126070
http://www.iteye.com/problems/126071
http://www.iteye.com/problems/126072
http://www.iteye.com/problems/126073
http://www.iteye.com/problems/126074
http://www.iteye.com/problems/126075
http://www.iteye.com/problems/126076
http://www.iteye.com/problems/126077
http://www.iteye.com/problems/126079
http://www.iteye.com/problems/126080
http://www.iteye.com/problems/126081
http://www.iteye.com/problems/126082
http://www.iteye.com/problems/126083
http://www.iteye.com/problems/126085
http://www.iteye.com/problems/126087
http://www.iteye.com/problems/126088
http://www.iteye.com/problems/126089
http://www.iteye.com/problems/126090
http://www.iteye.com/problems/126091
http://www.iteye.com/problems/126092
http://www.iteye.com/problems/126093
http://www.iteye.com/problems/126094
http://www.iteye.com/problems/126095
http://www.iteye.com/problems/126097
http://www.iteye.com/problems/126096
http://www.iteye.com/problems/126098
http://www.iteye.com/problems/126099
http://www.iteye.com/problems/126100
http://www.iteye.com/problems/126102
http://www.iteye.com/problems/126103
http://www.iteye.com/problems/126104
http://www.iteye.com/problems/126105
http://www.iteye.com/problems/126107
http://www.iteye.com/problems/126108
http://www.iteye.com/problems/126111
http://www.iteye.com/problems/126110
http://www.iteye.com/problems/126112
http://www.iteye.com/problems/126113
http://www.iteye.com/problems/126114
http://www.iteye.com/problems/126117
http://www.iteye.com/problems/126116
http://www.iteye.com/problems/126118
http://www.iteye.com/problems/126119
http://www.iteye.com/problems/126121
http://www.iteye.com/problems/126120
http://www.iteye.com/problems/126123
http://www.iteye.com/problems/126124
http://www.iteye.com/problems/126126
http://www.iteye.com/problems/126128
http://www.iteye.com/problems/126138
http://www.iteye.com/problems/126142
http://www.iteye.com/problems/126144
http://www.iteye.com/problems/126145
http://www.iteye.com/problems/126146
http://www.iteye.com/problems/126147
http://www.iteye.com/problems/126148
http://www.iteye.com/problems/126150
http://www.iteye.com/problems/126154
http://www.iteye.com/problems/126156
http://www.iteye.com/problems/126157
http://www.iteye.com/problems/126160
http://www.iteye.com/problems/126163
http://www.iteye.com/problems/126165
http://www.iteye.com/problems/126167
http://www.iteye.com/problems/126181
http://www.iteye.com/problems/126180
http://www.iteye.com/problems/126183
http://www.iteye.com/problems/126185
http://www.iteye.com/problems/126190
http://www.iteye.com/problems/126193
http://www.iteye.com/problems/126194
http://www.iteye.com/problems/126196
http://www.iteye.com/problems/126198
http://www.iteye.com/problems/126198
http://www.iteye.com/problems/126200
http://www.iteye.com/problems/126203
http://www.iteye.com/problems/126214
http://www.iteye.com/problems/126206
http://www.iteye.com/problems/126217
http://www.iteye.com/problems/126223
http://www.iteye.com/problems/126220
http://www.iteye.com/problems/126226
http://www.iteye.com/problems/126229
http://www.iteye.com/problems/126231
http://www.iteye.com/problems/126232
http://www.iteye.com/problems/126233
http://www.iteye.com/problems/126234
http://www.iteye.com/problems/126235
http://www.iteye.com/problems/126236
http://www.iteye.com/problems/126237
http://www.iteye.com/problems/126238
http://www.iteye.com/problems/126239
http://www.iteye.com/problems/126240
http://www.iteye.com/problems/126241
http://www.iteye.com/problems/126244
http://www.iteye.com/problems/126243
http://www.iteye.com/problems/126246
http://www.iteye.com/problems/126247
http://www.iteye.com/problems/126249
http://www.iteye.com/problems/126251
http://www.iteye.com/problems/126256
http://www.iteye.com/problems/126257
http://www.iteye.com/problems/126258
http://www.iteye.com/problems/126259
http://www.iteye.com/problems/126260
http://www.iteye.com/problems/126261
http://www.iteye.com/problems/126262
http://www.iteye.com/problems/126263
http://www.iteye.com/problems/126264
http://www.iteye.com/problems/126265
http://www.iteye.com/problems/126266
http://www.iteye.com/problems/126267
http://www.iteye.com/problems/126268