简体   繁体   English

在 Firemonkey 移动应用程序中保存对象本地数据的最佳方法是什么?

[英]What is the best method to save Objects local data in Firemonkey mobile app?

In my app I got JSON response from RESTServer.在我的应用程序中,我从 RESTServer 获得了 JSON 响应。 Then I convert them into Data Objects, store them in TObjectList and then bind the list to TListBindSourceAdapter for display.然后我将它们转换为数据对象,将它们存储在 TObjectList 中,然后将列表绑定到 TListBindSourceAdapter 进行显示。

I would like to save the TObjectList data to local storage.我想将 TObjectList 数据保存到本地存储。 My question is: what is the best method to save it?我的问题是:保存它的最佳方法是什么?

I tried to create a SQLite DB , I could save records into SQLite DB but it required to convert my TObjectList into DB records manually in code, and when I retrieve I need to convert it back to data object.我尝试创建一个 SQLite DB ,我可以将记录保存到 SQLite DB 中,但是它需要在代码中手动将我的 TObjectList 转换为 DB 记录,当我检索时,我需要将其转换回数据对象。 It involves more development effort.它涉及更多的开发工作。

Or should I use SaveState ?还是我应该使用SaveState I could save local data as string using SaveState.我可以使用 SaveState 将本地数据保存为字符串。 I could try to use TJson.ObjectToJson to convert Data Object into JSON and save it.我可以尝试使用 TJson.ObjectToJson 将数据对象转换为 JSON 并保存。 To do this, I could save the TObjectList into Array, store it into a data object and do convert to JSON.为此,我可以将 TObjectList 保存到数组中,将其存储到数据对象中并转换为 JSON。 when retrieve I could convert back using TJson.JsonToObject.检索时我可以使用 TJson.JsonToObject 转换回来。

Or is there any better method to do so?或者有什么更好的方法可以做到这一点? Is there a common method to save local data in Firemonkey? Firemonkey 有保存本地数据的通用方法吗? Is there something similar to State Management in Angular?是否有类似于 Angular 中的状态管理的东西?

At last, I used SaveState to save my data to local.最后,我使用 SaveState 将我的数据保存到本地。 Since I tried and found using SaveState is much faster to develop and easier to develop.由于我尝试并发现使用 SaveState 开发速度更快且更易于开发。

The disadvantage of using saveState instead of saving into a local DB is, SaveState only happens when the application form closed, or in a mobile app, when the app deactivated.使用 saveState 而不是保存到本地数据库的缺点是,SaveState 仅在应用程序表单关闭时或在移动应用程序中,当应用程序停用时发生。 If the app in mobile app been killed directly instead of deactivating, the SaveState is not called and data may lose.如果手机应用中的应用直接被杀死而不是去激活,则不会调用SaveState,数据可能会丢失。 Conversely, saving into local DB can be called manually anytime.相反,可以随时手动调用保存到本地数据库。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM