Android数据存储实现的5大方式

数据存储在开发中是使用最频繁的,在这里主要介绍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

时间: 2024-11-05 19:38:14

Android数据存储实现的5大方式的相关文章

Android 数据存储方式分为哪几种?

10道题值得思考 第一道题 1.Android 数据存储方式分为哪几种? SharedPreferences存储数据 2. CotentProvider内容提供者 3. 文件存储 4. 数据库存储(Sqlite) 5.网络存储 2. NDK是什么? 1. 一系列工具类的集合 2. Arm指令集 3. NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将so和java应用一起打包成apk.这些工具对开发者的帮助是巨大的. NDK集成了交叉编译器,并提供了相应的mk文件隔离

android 数据存储的几种方式

总体的来讲,数据存储方式有三种:一个是文件,一个是数据库,另一个则是网络.其中文件和数据库可能用的稍多一些,文件用起来较为方便,程序可以自己定义格式:数据库用起稍烦锁一些,但它有它的优点,比如在海量数据时性能优越,有查询功能,可以加密,可以加锁,可以跨应用,跨平台等等:网络,则用于比较重要的事情,比如科研,勘探,航空等实时采集到的数据需要马上通过网络传输到数据处理中心进行存储并进行处理. 对于Android平台来讲,它的存储方式也不外乎这几种,按方式总体来分,也是文件,数据库和网络.但从开发者的

Android——数据存储(四种方式之一)SharedPrefereces

Android--数据存储(四种方式) 1.SharedPrefereces   轻量级.XML  存储文件名,数据保存在data/data/basepackage/shared_prefs/myopt.xml中   实例-收藏-记住密码自动登录 //一种轻量级的数据存储方式//通过KEY 存入数据--putxxxx(key,value) 取出数据--getxxxx(key  default)   2.读写SD卡  SD的根目录  适用于数据流读写 3.SQLite  轻量级.dp文件多用于手机

Android数据存储技术五大方式总结

本文介绍Android平台进行数据存储的五大方式,分别如下: 1 使用SharedPreferences存储数据 2 文件存储数据 3 SQLite数据库存储数据 4 使用ContentProvider存储数据 5 网络存储数据 下面详细讲解这五种方式的特点 第一种: 使用SharedPreferences存储数据     适用范围:保存少量的数据,且这些数据的格式非常简单:字符串型.基本类型的值.比如应用程序的各种配置信息(如是否打开音效.是否使用震动效果.小游戏的玩家积分等),解锁口令密码等

Android——数据存储(四种方式之二)读写SD卡

Android--数据存储(四种方式) 1.SharedPrefereces 只能保存一些简单的数轻量级.XML  存储文件名, 数据保存在data/data/basepackage/shared_prefs/myopt.xml中    实例-收藏-记住密码自动登录 //一种轻量级的数据存储方式//通过KEY 存入数据--putxxxx(key,value) 取出数据--getxxxx(key  default) 2.读写SD卡  SD的根目录  适用于数据流读写 实现步骤:加入读写SD卡权限

Android数据存储之GreenDao 3.0 详解(一)

前言: 今天一大早收到GreenDao 3.0 正式发布的消息,自从2014年接触GreenDao至今,项目中一直使用GreenDao框架处理数据库操作,本人使用数据库路线 Sqlite---->OrmLite---->GreenDao.今天白天一直在忙着公司的项目需求,只能晚上加班来学习最新的GreenDao 3.0使用方式了. GreenDao 介绍: greenDAO是一个对象关系映射(ORM)的框架,能够提供一个接口通过操作对象的方式去操作关系型数据库,它能够让你操作数据库时更简单.更

android数据存储_概述

andorid提供了六种方式存储永久的数据,根据需求来使用不同的存储方式,例如是否对于应用程序时私有还是公有,数据存储的空间等. 六个存储方式: 使用SharedPreferences: 这种方式是使用键值对来存储私有的数据 内部存储: 在设备的内存中存储私有数据 外部存储: 在SD卡或其他的外部存储来存储公有数据 SQLite数据库: 在私有的数据库中存储私有的结构花数据 网络存储: 在网络服务中存储数据 私有数据一般情况下不能被访问,但是可以通过content provider来进行对数据的

android数据存储_内部存储

源码下载(免下载积分):下载 你可以直接存储数据到内部存储中,默认情况下,文件存储到内部存储中是私有的,不能被 其他程序访问,当卸载应用程序,这些文件会被移除. 创建并写入数据可以有两种方法: 使用java中的相关的方法, 使用android.content中的相关方法,  调用 openFileOutput(),并返回FileOutputStream对象 调用FileOutputStream对象的write()方法 关闭流 读文件也是基本相同的方式. 在读文件有一点小技巧:如果想在编译时保存一

Android数据存储之SharedPreferences浅析

SharedPreferences 是 Android 数据存储方式中的一种,特别适合用来存储少量的.格式简单的数据,比如应用程序的各种配置信息,如是否打开音效,是否开启震动等等. SharedPreferences 存储数据的位置和格式 SharedPreferences 将数据以键值对的形式,存储在 /data/data/<package name>/shared_prefs 目录下面,以 XML 的格式保存,该 XML 文件的根元素是 <map.../>,该元素里每个子元素代