简体   繁体   中英

Android data best practices

I am building an Android app that that involves taking pictures and adding text to it. In other apps I have built I have been storing the data locally as JSON data. I read that you should always save locally(JSON) at every step because you can never be sure when an activity will be stop.

In the app I am currently building I want to upload the data to a SQL database. For example want to take a picture, save it locally and edit it(while saving at every edit), and then upload it to server. Then I would want to display a list that accesses the database to display finished photos.

Can I continue to save things with JSON and then only upload certain things to the database or should I skip JSON and just go directly to database?

Is there any built in methods for sending JSON data to a SQL database? Just trying to figure out the best way to go about this. Any advice would be appreciated.

I would not store the data as JSON because you might need later to query the data or filter it which will be cumbersome to do it with JSON.

What I suggest that you store your data in sqlite (the text only) and then when you are about to send to the server you can serialize it as JSON.

There is no special method to send JSON data, it is just normal plain text over HTTP.

As general rule, data storage should be in a database and then you can use JSON (or XML) to exchange the data (eg sync it with the server)

Also, if you are sending large amount of data, consider compressing it before sending to the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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