使用哪种 Android 数据存储技术? [英] Which Android Data Storage Technique to use?

查看:16
本文介绍了使用哪种 Android 数据存储技术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android 文档有以下选项,但没有解释每种情况最适合什么情况.每种方法的优缺点是什么?例如在什么情况下 SQL 会比共享首选项更好?

The android documentation has the following options below but does not explain what circumstances each is best for. What are the pros and cons of each method? e.g. Under what conditions would SQL be better than Shared Preferences?

  • 共享偏好
  • 内部存储
  • 外部存储
  • SQLite 数据库
  • 网络连接

推荐答案

Android 中的不同存储选项

  • 考虑从 application1 添加到设备的结构化数据是同一设备中存在的另一个应用程序 2 无法访问,但application1 添加到设备的个人资料照片可用于在同一设备上运行的 application2

  • Consider the structured data added to the device from application1 is not accessible to another application2 present in the same device but the profile photo added to the device by application1 is available to the application2 running in the same device

把安卓设备看成一个城市,里面的应用程序是城市中的房屋,房屋中的人(应用程序)是数据.现在内容提供者就像城市中的经纪人(Android 设备).该经纪人为城市中的人们提供了寻找的途径不同的房子指的是android中的内容提供者设备为不同的设备提供对设备中数据的访问应用程序.

Consider android device as a city, the applications in it are the houses in the city, people in the houses(application) are the data. Now content provider is like an broker in the city(android device). This broker provide access for the people in the city for finding different houses referring as the content provider in the android device provide access for the data in the device for different applications.

  • 考虑我有一个应用程序说我用来登录的面子书应用程序我的帐户.

  • Consider I have an App say a Face book App which I use to log in to my account.

现在我第一次输入我的用户名和密码来获得访问我的帐户.假设我一小时后退出应用程序我再次使用同一个 Facebook 应用程序再次登录我的应用程序.

Now the very first time I enter my username and password to get access to my account. Say I log out of the application an hour later again I use the same Face book App to login again to my application.

我必须再次输入用户名和密码才能登录我的帐户我为我的应用程序设置了一个主题,并为我的应用程序设置了其他设置看看我现在的手机

I have to enter username and password again to login to my account and I set a theme to my application and other settings on how my app looks in my current phone

这是不必要的,因为考虑到我正在使用手机登录应用程序.所以我会一直用我的手机重新登录再次,因此一次又一次地输入我的凭据是更多的工作表明它不是一个用户友好的应用

This is un-necessary because consider I am using my phone to login to the application. So I will always use my phone to login again and again, thus entering my credentials again and again is more work shows it’s not a user friendly app

Shared Preferences 在我可以使用的场景中非常方便它的功能是在一个 xml 文件中共享我的数据,该文件物理存在于安装在我手机上的 Android 应用程序,即使它也不会被破坏该应用程序已关闭.在这里我们可以保存用户的偏好数据当前应用程序.

Shared Preferences is very handy in such scenarios where I can use its feature to share my data in a xml file Which physically exists in the Android app installed in my phone which is not destroyed even if the app is closed. Here we can save user preferences data of the current application.

因此,下次我在手机中打开应用程序时,我可以看到数据自动填写必要的字段和设置

As a result next time I open my app in my phone I can see the data automatically filled in the necessary fields and the settings are

  • 在Android中我们可以使用设备存储空间来存储数据它用于应用程序.数据类型涉及诸如文本文件、图像文件、视频文件、音频文件等

  • In Android we can use the device storage space to store the data in it for the applications. The type of data involves things such as a text file, image file, video file, audio file etc.

如图所示我们可以看到有两个地方可以做这个.一种方法是将原始文件写入主要/次要贮存.另一种方法是将缓存文件写入主/辅助存储.

As seen in the figure as we can see that there are two places we can do this. One way is to write the raw files into primary /secondary storage. Another way is to write the cache files into the primary/secondary storage.

存储原始数据和缓存数据也有区别,用户曾经存储在内存中的原始数据必须明确由用户明确删除,否则它将一直存在到那时.存储在内存中的缓存数据不是永久数据,因为系统觉得不足时会自动删除记忆.

There is also difference between storing raw data and the cache data, the raw data once stored in memory by user has to be explicitly deleted by the user explicitly otherwise it would exist till then. Cache data stored in memory is not a permanent data because the system automatically deletes it if it feels there is shortage of memory.

内部存储:

  • 考虑应用程序中的用户已将数据存储在内部存储,那么只有该应用程序的用户才能访问该手机上的数据,这些数据会在用户卸载应用程序.说到内部存储器是什么私人.

  • Consider a user in an application has stored data in internal storage, then only that user of that application has access to that data on the mobile and that data is automatically deleted when the user uninstalls the application. Speaking of which internal memory is private.

应用程序内部存储目录使用名称包存储在 android 文件系统中的特殊位置命名.

The apps internal storage directory is stored using the name package name in a special place in the android file system.

其他应用或当前应用的用户无权访问由特定用户和特定应用程序,除非它是明确制作的可供用户进行可读/可写访问.

Other apps or users of current app have no access to the file set by a particular user and a particular app unless it is explicitly made available to the user for readable/writable access.

  • Sqlite 用于在移动设备本地存储更多结构化数据运行 android 应用程序的位置.结构化数据涉及截至图中以学生信息的形式显示行和列.

  • Sqlite is used to store more structured data locally in a mobile where the android app is running. Structured data involves as of which shown in the figure like a student’s information in the form of rows and columns.

Sqlite 提供类似 Mysql 和 oracle 的功能,但具有有限的功能特性.有些事情涉及表演对表的查询操作.虽然有一些功能,比如创建视图,但还有一些功能(如存储过程)不可用.

Sqlite offers similar functionality like Mysql and oracle but with limited functional features. Some of the things involve performing query operations on tables. There are features though like creating views but also some features are not available like stored procedure.

Sqlite 在存储复杂的大数据方面非常有帮助,这些数据可以下载一次,可以反复使用,直到应用程序在跑.当应用程序关闭时,sqlite 数据库是也被毁了.

Sqlite is very helpful in storing complex and large data which can be downloaded once and can be used again and again until the application is running. When the application is closed the sqlite database is also destroyed.

这篇关于使用哪种 Android 数据存储技术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆