简体   繁体   English

我可以在一个项目中使用两种不同的数据存储吗?

[英]Can I use two different data storage in one project?

I want to use sharedpreferences in my login form, but i also want keep XAMPP as my main storage. 我想在我的登录表单中使用sharedpreferences,但我也想保留XAMPP作为我的主要存储。 What is the best data storage when I want to do my app in offline mode? 我想以离线模式进行应用程序时最好的数据存储是什么?

If you want to store data in locally then you can use SQLite Database and yeah XAMPP is whole different thing to store data for this you need to create APIs to communicate with database. 如果要在本地存储数据,则可以使用SQLite数据库,是的,XAMPP完全不同,因此需要创建API与数据库通信。

You can also use Sharedpreferences for storing the data but Sharedpreferences will store data with the key-value pair only. 您也可以使用Sharedpreferences来存储数据,但是Sharedpreferences将仅存储具有键值对的数据。

But you can use both for different different purposes for the same app 但是您可以针对同一应用将二者用于不同的目的

Yes, you're allowed to mix and match any type of data storage you wish because none of them were designed to be in conflict with each other. 是的,您可以混合和匹配所需的任何类型的数据存储,因为它们之间都不存在相互冲突的设计。

However, it's a good idea to understand what type of data storages is available for you to use, because different types of storages has different benefits and drawbacks. 但是,最好了解可用的数据存储类型,因为不同类型的存储具有不同的优缺点。

SharedPreferences is a great way to store a user's preferences, or simple data with a single value. SharedPreferences是一种存储用户的首选项或具有单个值的简单数据的好方法。 It's great for storing a user's preferences because when creating Settings, it's extremely common to use Preferences which directly reflects the values within your SharedPreferences. 存储用户的首选项非常好,因为在创建设置时,使用首选项直接反映您的SharedPreferences中的值是非常普遍的。 However, due to it's design, SharedPreferences isn't a good idea to store large amounts of data or dynamically created data. 但是,由于它的设计,SharedPreferences不是存储大量数据或动态创建的数据的好主意。

For that, it's better to use a database and you're free to use any type of database you wish. 为此,最好使用数据库,而您可以自由使用所需的任何类型的数据库。 But for offline mode, it's best to use the SQLite Database that's offered by Android by default. 但是对于离线模式,最好使用默认情况下Android提供的SQLite数据库。

However, if you do want to use XAMPP, it's not uncommon to see developers who store their full data in an online database, but cache a few data within a local database like SQlite. 但是,如果您确实想使用XAMPP,看到开发人员将全部数据存储在在线数据库中,但在本地数据库(例如SQlite)中缓存一些数据的开发人员并不少见。

Therefore, there's zero conflicts among data storage options, so mix and match to what benefits your app's design best. 因此,数据存储选项之间的冲突为零,因此可以混合使用,以最大程度地受益于您的应用程序设计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在两个不同的应用程序中使用一个GCM项目编号来接收GCM推送吗? - Can i use one GCM project number in two different app for receive Push of GCM? 我可以在一个项目中使用2个清单吗? - Can I use 2 manifests in one project 我可以对一个片段使用两个viewmodel吗? - Can I use two viewmodel for one fragment? 我们能否从一个项目中获得两个不同的apk(一个自定义和一个通用) - Can we have two different apk(one custom and one general) from one project 我可以在不同的活动中为两个不同的列表视图使用相同的适配器吗? - Can I use the same adapter for two different listviews in different activities? 我们可以在两个不同的活动类中使用一个片段吗 - Can we use one Fragment in two different Activity Class 我可以将两个Google Analytics(分析)帐户添加到一个android项目中吗 - Can i add two Google Analytics account to one android project 我可以在不同页面的项目中使用 FB 和 Admob 广告吗 - Can i use FB and Admob ads in a project on different pages 我可以为一个按钮设置两种不同的 onclick 方法吗 - can I have two different onclick methods for one button Play商店中一个应用的两个不同项目 - Two different project for one App in Play Store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM