Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In my application, on every launch at first some JSON have to downloaded from server and later I need to show various information by parsing this data one the full app life-cycle. The JSON object is pretty big with almost 5000 JSONArray. Every JSON array is of the following form:
[37,101,"The Blocks Problem",9952,0,1000000000,0,852,0,0,11197,0,16606,0,7279,200,18415,5325,14492,3000,1]
So I have two option:
Save the json string into a file and later read it.
Save the JSON array in SQlite database with almost 10 columns and 5000 rows.
The first option seems to be efficient. But later I have to manipulate the JSON for displaying various information. In some cases, I need to search full array to pick on array information and there are many cases like this. So this would be very time consuming also.
The second option is better for searching and displaying faster. So I approached on with the second option. But the insertion of 5000 rows at a time is time consuming also. I did it in AsyncTask for betterment but it is taking too much time to be executed - parsing JSON and store in SQlite table.
So what can I do? what is the best way to store this huge information and later use it efficiently?
I answered a question pretty close to this today - File or Database? - Best Practice to save Objects on Android-Device. I wanted to add that if inserting 5000 rows is taking too long, try adding them all in a single transaction, or using a bulk load mechanism. It's worth the effort to figure out your insert problem instead of trying to use files.
See this tutorial about bulk loading SQLite
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
My question is whether it is more efficient to getChildren in a query and then have all your if else statements sorting the data
Or whether it would be better to have multiple calls to the database which are obviously already sorted?
I would assume getting the children would be better since you are only making one call to the database?
My question is whether it is more efficient to getChildren in a query and then have all your if-else statements sorting the data Or whether it would be better to have multiple queries which are obviously already sorted?
Reading all the data within a node at once sounds not as a good solution to go ahead with. When you attach a listener on such a reference, you are reading all direct children that exist beneath that node, including the nested ones. Filtering the results on the client might be considered a waste of bandwidth and resources.
Suppose you have a node with 1000 objects and you are looking for only three of them. Imagine what would be the size of the result set when getting all 1000 objects? I can imagine that it will be huge. So the best option that you have is to use a query a do the filtering directly on the server. In this manner, the size of the result set will be very small, because only three elements will be returned and not 1000. So basically you are getting only the results you are interested in.
I would assume getting the children would be better since you are only making one call to the database?
That's actually the opposite. There nothing wrong in creating multiple Firebase database calls.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am developing my school's timetable app for android. I am getting timetable data from MySQL database. -> I have access to the timetable, only when I have an internet. But I want to make timetable accessible without the internet. I read that I need to save data from MySQL to the SQLite, and then use them. Can you, please, give me links to the samples how do to that?
I can point you in a direction that you might want to go in, you can try to use a ContentProvider to store and read data on your device offline. Once you create your ContentProvider, make use of your school's API through an AsyncTask (provided you have permission to access it) to format you some JSON to parse in Java with a library like Gson.
Basically this relationship becomes like this:
(Server)----JSON---->(AsyncTask)---->(Parse JSON in Client)---->(Move Parsed JSON data to your app's ContentProvider).
There are numerous articles on things like this:
ContentProvider example:
https://developer.android.com/guide/topics/providers/content-provider-creating.html
(Udacity also has free videos describing ContentProviders and JSON retrieval and parsing.)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am starting with a new app i which i will be needing web services.All the data will be coming from the data base.My database will look something like this
Id
Name(Birds Name)
Description
Date
Image for that Name
Now i want to give all the values to user in json array.But i am confused on few points
How will i send images in json array
Is it correct to store Images in Database?
There may be 3-5 images for a particular name,so do i create a different table for images with foreign key??
P.S-Also it would be grateful if some one can give me link on how to make a web-service which i can consume in my android application
To answer your questions:-
To send images in JSON Array, you need to convert your images into BASE64 first and then add it in your JSON Array object. This BASE64 type can be received on the webserver and a reverse operation could be performed to get the actual image.
NO. Images are never stored in Database. Rather store their corresponding path. Its always better to save images on the external storage.
Yes. You can create a separate table, but to store the path of images, not the images itself. You can then use foreign key to acces the images path and then the images respectively.
Regarding the techno, I use Google App Engine + Endpoints. A good choice, because endpoints generate with Maven the model for the Android app based on your AppEngine datastore.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In my app i want to add a new feature that consist in having a list of object's bought by the user. So, when the user buy something he add's that object to the list. Later, if he starts the app again,there should be all the items added in the list.
The object will have some parameters (name, bought date, price, etc etc). My question is: is this a case to use sqlite?
If yes, In the activity with the list of the objects, everytime the activity starts I will have to load the table from database?
The answer to your first question is "yes". The answer to the second is, also, "yes".
Should I use sqlite?
Well, it depends on your preference and the scenario,
If you are using a webserver and updating the webserver, no need
to use a sqlite since you can ping a query to server and show the
objects for the list
If you are not using a webserver you can use Sqlite for this
scenario since you can perform all the
CRUD(Create,Read,Update,Delete) operations for the Sqlite
Advantages and disadvantages of using SQlite
Pros:
If your application gets closed the in memory data will be lost, but after that you will be able to restore the state from the database if you have one
Especially for the case of complex calculations it is good to store the result once in the database and not recalculate it multiple times on demand
The database will untie your UI from the internet connection and thus you will be able to display results even if there is not internet connection
Using database you will be able to fetch the updated data from a background service, without impacting your UI
Organizing your data in database usually makes it a lot easier to manage all the application data.
Cons:
Adding database will require a bit of additional effort on your side
Sinple Line :: Go for Sqlite solution
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
what are the best practices to save content data when the device is offline or when you have already downloaded some content that shouldn't be retrieved from server again?
Is SQLite the best approach to achieve this? If the information that I want to store is retrieved from an API as a JSON should I create a database structure to parse and insert it?
I know that the above are different questions but the purpose is the same.
Using Sqlite is a bad idea as it is extremely slow and takes up a lot of unnecessary space. When possible serializing objects or using SharedPreferences should be prepared to sqlite (unless of course you have a database structure). For caching and storing data pulled from the internet, I recommend robospice: https://github.com/octo-online/robospice. It's a very well done library, easy to use, and should be used any time you download data from the internet or have a long-running task.
I would say that it depends on the type of data you're saving. Sqlite is not always a bad idea. It's slower than storing an array in memory, but if you're handling a 500-entry address book an array is going to be a lot more clunky than a database.
Robospice looks interesting.