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.
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
this is the first time that I need to store some data permanently so I would like some suggestions before to proceed. I've read that there are different ways to store data on an Android device:
Internal storage
Shared Preference (but if I've understood is just for symple data like an option)
Shared storage (but I don't need to share data among other apps)
Database
I can't understand what is the best option for me between the first and the last.
My case
I have a list of book with title, subtitle, cover image and each book contains a list of cards with title, optional image, (audio if possible), other stuff.
So, I have to store an arraylist of a custom class that includes another arraylist of anothercustomclass and some text/image
Which approach should I take?
Thanks
Frankly, the case description is much too limited to give an informed advice (so the question should be closed).
But if you have doubts, then the safe / default choice is the database. It might come with big overhead for some cases (like when it's enough to serialize the whole arraylist to a blob and store as a single file), but you are less likely to paint yourself into a corner.
Addition (after a comment)
When using a database, you don't store objects directly (because what an sql database stores are "relations" which you can think of as "sets of rows", not objects). Instead you have some code (custom or from a library) that translates an object into a row (or multiple rows) for storage and some code that translates it the other way.
If you want to store the actual objects, then serialization to a file is pretty much the only way.
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 4 years ago.
Improve this question
I am trying my hands on Room and RxJava. I fairly new to both. My code is working fine but I was interested to know about the best practices.
Imagine an object with 10 fields say CompleteSong. In my app, I am making room return a Flowable<List<CompleteSong>> Whenever I make an update in the database, the Flowable updates with all the values. I am displaying that list with a RecyclerView. I have two possibilities to proceed with i.e.
1. I can store the object that is being changed and wait for the Flowable to update. When the flowable updates I update 1 item of RecyclerView
2. I can update the RecyclerView when the Flowable updates parsing through the list and looking for the changed instance of CompleteSong
I used to use the former approach, it seems to be less reactive but optimized whereas the latter seems to be more reactive but at the same time less optimized.
Can someone instruct me on this, what should be done? What approach should I follow or there's something else that I couldn't discover.
Note: I am new to reactive, so please consider updating me on the terminology if I messed something up.
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've a single data table, fully structured, that my app will require.
It consists of a few thousand rows, three columns separated by spaces (in the text file I load from), and I need these to have specific priority assigned to them.
That priority is stored as an int and will be modified.
I considered keeping the whole thing in memory (it's fairly short strings), and simply writing to text with updated int values at the end of a session. An alternative approach would be a single sqlite table that I update as the app functions.
I'm sure it's fine either way, but just out of curiosity, which would perform worse, reading/writing to sql table or text parsing?
As stated by #Rotwand, you should go for a database just for the whole abilities provided. Text parsing may be faster only if you only access to first/last rows, or maybe select data sequentialy in the order.
In other cases, trying to optimize text parsing will lead you to something equivalent to database, thus, no need to reinvent the wheel.
Text parsing (or serialization) may also be an option if you have specific needs (complex object structures, very few objects, ...) but database should still be a good thing at least to have more access options.
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 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