Issue
I'm working on an app that will retrieve a colors.json file from server. This file will have the following structure:
[
{"ServerActionButton.background.normal":
{ "red": 29, "green": 188, "blue": 189, "alpha":255}
},
{"ServerActionButton.background.disabled":
{ "red": 164, "green": 228, "blue": 229, "alpha":255}
},
{"ServerActionButton.title.normal":
{ "red": 255, "green": 255, "blue": 255, "alpha":255}
},
...
]
This JSON should be retrieved on app startup, and I should be able to use these colors throughout the whole app.
Question: What's the best way to do this? I've thought about the following options:
- Generating a resource XML file from the JSON (it would be great, but is it possible?).
- Mapping the JSON to a model, and then storing it in SharedPreferences.
- Building a local database with the data retrieved from the JSON.
Which would be the best approach? Is there some other possibility I'm not considering?
Thanks in advance!
Solution
First download json color data.
Case 1 :- If you have small amount of data in json color then use SharedPreferences.
Case 2:- If you have large amount of data then go for the SQLite database
For my personal opinion SQLite is best idea for that so you can manage eaisly using query.
If you want to use SharedPreference then you can.
SQLite
Large amounts of same structured data should be stored in a SQLite database as databases are designed for this kind of data. As the data is structured and managed by the database, it can be queried to get a sub set of the data which matches certain criteria using a query language like SQL. This makes it possible to search in the data. Of course managing and searching large sets of data influences the performance so reading data from a database can be slower than reading data from SharedPreferences.
SharedPreferences
SharedPreferences is a key/value store where you can save a data under certain key. To read the data from the store you have to know the key of the data. This makes reading the data very easy. But as easy as it is to store a small amount of data as difficult it is to store and read large structured data as you need to define key for every single data, furthermore you cannot really search within the data except you have a certain concept for naming the keys.
Answered By - Arpit Patel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.