android中数据存储
16lz
2021-01-23
android中数据存储 Android 中存储数据的方式有五种:SQLite数据库、文件存储、内容提供者、网络、SharedPreferences(Key----value)五种存储方式。 其中SQLite:是才用动态存储数据类型,会根据存入值自动的判断,SQLite具有以下五种数据类型: 1:NULL,空值类型 2:INTEGER:带符号整数,具体取值取决存入数值范围大小。 3:REAL:浮点数字 4:TEXT:文本类型 5:BLOB:二进制对象此外,其它类型的数据,其也支持,在SQLite中,当主键的类型为整数类型的时候,主键默认是在数据库中当前最后一个值的基础上自增1的。 有的时候我们需要去查看数据库中存储的table信息,此时有两种方式去查看,第一种:下载一个SQLite Developer,一个可视化的图形界面,导入相关的*.db文件就可以查看相关table信息,这里重点介绍第二种:cmd黑屏下面查看table信息。1>切换到安装android 软件的platform-tools(这里我是到Google 的android 官网下载的一个集成各种AVD,Android SDK等的Eclipse)目录下。2>输入adb shell,此时将会进入一个类似Linux系统根目录下3>root@android:/# (我将其标记别名为root)4>root ls5>root cd data6>root@android:/data #(标记为d1)7>d1 cd data8>root@android:/data/data #(d2)9>d2 切换到该表操作所在的对应包的目录下(activity所在Package,标记为really root)10>really root ls11>really root cd databases(标记为db)12>dc sqlite3 mydb.db(*.db为db文件名,此时可以进入sqlite3目录下)13>输入.tables若是要查看某个文件内容,其前面10步是一样的,只是从11步开始切换到 cd files,再输入cat.file.txt(文件名)既可以查看文件。
Android 中File操作其中设计File的操作,主要有一个属性,MODEL,取值有五种MODE_APPEND:if file is exist,we can append to file lastMODE_PRIVATE:the file can be access to this classMODE_WORLD_READABLE:the file only can be readMODE_WORLD_WRITEABLE:the file only can be writeMODE_WORLD_READABLE+MODE_WORLD_WRITEABLE: the file can be read and write
SharedPreferences对象存储信息其默认生成的文件类型为*.xml格式的,查看文件信息命令为:cat *.xml,SharedPreferences对象主要是用于保存配置信息的。大致使用方式为SharedPreferences pref = CurrentActivity对象.this.getSharedPreferences("文件名",Context context);以Eidtor对象以Map键值对保存信息Editor editor =pref.edit();editor.putString(String key,String value);editor.putInt(String key,int value);editor.commit();//此步骤必须执行,否则将不会保存,即事物没提交一样//==========相应取值方法为===============pref.getString(String key,String value);pref.getInt(String key,int value);
Android 中File操作其中设计File的操作,主要有一个属性,MODEL,取值有五种MODE_APPEND:if file is exist,we can append to file lastMODE_PRIVATE:the file can be access to this classMODE_WORLD_READABLE:the file only can be readMODE_WORLD_WRITEABLE:the file only can be writeMODE_WORLD_READABLE+MODE_WORLD_WRITEABLE: the file can be read and write
SharedPreferences对象存储信息其默认生成的文件类型为*.xml格式的,查看文件信息命令为:cat *.xml,SharedPreferences对象主要是用于保存配置信息的。大致使用方式为SharedPreferences pref = CurrentActivity对象.this.getSharedPreferences("文件名",Context context);以Eidtor对象以Map键值对保存信息Editor editor =pref.edit();editor.putString(String key,String value);editor.putInt(String key,int value);editor.commit();//此步骤必须执行,否则将不会保存,即事物没提交一样//==========相应取值方法为===============pref.getString(String key,String value);pref.getInt(String key,int value);
更多相关文章
- Android:获取APK签名信息
- Android 签名类型
- Android的数据处理:使用annotation实现JSON字符串解析为java对象
- Android中的Context对象
- Android获取SDK的版本信息
- 获取android联系人信息
- Android 存储用户信息
- android 获取 imei号码以及其他信息