I am writing a card-game application.
I represent the Deck of cards using an ArrayList<ImageView>, and i represent the "cards stacking up on the table"(For rollback purposes) in a Stack<ImageView>.
How can I store the state of both the ArrayList<ImageView> and the Stack<ImageView> in order to pick up from where i left off earlier.
I can only think of SharedPreferences, which only supports primitives and Sets.
Your might want to consider using a SQLite database for this. Your columns would be the properties on the object you want to store. If you add on "order" property you can then use the SQL logic
order by `order` DESC
at the end of your query to get them back in the correct order.
Here's a guide:
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/
Related
As per the title,
I have been confused on how I would implement the following:
A FlashCard deck has a title, due date (both have been implemented).
However, it also contains a List of Cards.
A Card is made up of a question and answer.
Like this, Deck(title, duedate, flashcards). Cards(question, answer)
I have been thinking about using a dedicated typeconverter for this. However,
it can also get messy.
For example,
I was thinking of having a type converter which collects all the existing questions and answers into a concatonated csv string. Then it will deconvert this when transitioning back into the object.
This method seems quite complicated. Therefore, I was wondering what is the best practice per se, for this sort of thing.
Thanks...
I do think your problem is a database schema problem. So basically there are 2 solutions depending on how you want to use the cards.
1. If the card does not repeat in any deck or if each and every card is unique:
Then you can use this schema:-
For finding all cards for a particular deck say suppose "Deck 1" whose id is 1. You can use the SQL query "SELECT * FROM Cards WHERE Deck_id=1;"
Pros:
You will have to maintain only two tables.
Probably easy to write SQL Queries.
Cons
You cannot reuse any cards. All cards will be unique.
May require more storage space.
2. If the card repeats, or if you want to reuse a card:
Then you can use this schema:-
For finding all cards for a particular deck say suppose "Deck 1" whose id is 1. You can use the SQL query "SELECT * FROM Cards WHERE id IN(SELECT Cards_id FROM Deck_has_Cards WHERE Deck_id=1);"
Pros:
Saves a lots of storage space(if cards are not unique).
Cons
Queries become very hard to write
I will recommend you to check for better SQL queries than those I have written.
If you are using Room Database use #Query(<SQL>)...(I am not expanding on this many tutorials are available).
I will not recommend the way you are trying to store the cards as it will be not working with the A.C.I.D. properties of the database.
Is there any way to select specific properties from firebase Realtime Database? I know there is a way to retrieve selected properties from firestore but how can get via Realtime database using Node.js
I want only Notes from everyone nothing else.
Suppose i just want to select Notes from Allergy here is my sample code which i tried but not successes...
admin.database().ref(`vitals/Allergy`).select('Notes').then(result => {//here is my result.....})
But it shows me that select is not a function.......
Realtime Database doesn't support "projections" like this (neither does Cloud Firestore). If you are going to query across multiple child nodes, you are going to get each entire child node that matches the query. Even if you want just one property of each child, you can't avoid the cost of downloading the entire child.
If your app is very sensitive to performance on these types of queries, consider duplicating the data such that there is another branch of your database that contains only the "Notes" property, and query that branch alone. This duplication is common in NoSQL type databases, and is call the "fan out" technique.
If you want to save download band then i can't help you further, otherelse:
let ArrayOfAllDownloadedNotes = [];
firebase.database().ref('yourRootFolders/vitals/Allergy').once((snapshot)=>{
ArrayOfAllDownloadedNotes = [...ArrayOfAllDownloadedNotes, snapshot.val().Notes];
});
//Reapeat the firebase formula for every child you want retrieve the Notes from
//You may also use forEach((item)=>{}) function for each folder you want to retrieve the //notes from if you want
console.log(My Array of Notes:',ArrayOfAllDownloadedNotes );
I put my data in 3 tables(Links, Images and PDF)
each table has columns(university, faculty, grade, and description,...)
I want to retrieve description column in the 3 tables.
where university, faculty, and grade equal to certain values.
and sort them with creation date.
how can I perform that query in parse?
I'm not familiar with Android, but I'm pretty sure Parse does not support "Join" in the way a SQL database does. You could nest the queries, performing the next one in the previous one's completion block.
However, if you regularly want to get data from those 3 tables, I'd suggest you make it 1 table instead, with a column "Content" instead of Link/Img/PDF. Images and PDFs would probably be stored as PFFiles anyway, and you can put link as either its own string column or putting it in a file. You could also add a column "type" if you want to be able to query a specific type, or just keep track of which columns contains which data.
Then you could query the "Content" class, on the keys you want.
I think this link might help you
https://parse.com/docs/js/guide#relations and it is quite simple and nicely explained . You can't do it directly in the database, though.
I need to synchronize the data in my application. I do the request to the server, bind and use copyToRealmOrUpdate(Iterable<E> objects) to add or update this data to the database.
But my files can be invalidated and I need something to delete everything that don't have at the data that return at the request. I don't want to truncate or do a manual delete to do this because performance matters.
IDEA 1
#beeender
What do you think about use the PRIMARY_KEY of the table to delete the data that I don't want (or I don't need)?
Looks like:
1º: If the database was populated, get all primary key and add it in an HashMap (or anything that do the same).
2º: Update the data or add, removes the item of the HashMap (using the primary key) if it was updated or added.
3º: Remove all items of HashMap on the Realm.
Maybe the In memory Realm would be a good choice for you in this situation. You can find related documents here .
By using the in-memory Realm:
The db will be empty when you start a new app process
After you close all the instances of the Realm, the data will be cleared as well.
----------------------------------- Update for deleting data for normal case -----------------------------------------
For deleting, there are some options you can use
Remove all data for a specific model, see doc
realm.allObjects(MyModel.class).clear();
Remove entire data from a given Realm by (Realm API)[https://realm.io/docs/java/latest/api/io/realm/Realm.html#deleteRealm(io.realm.RealmConfiguration)] (close all instances first!):
Realm.deleteRealm(realmConfig);
Or just remove the Realm file through normal java API.
If you really care about the performance, you could consider to separate those data in one Realm, and use option 2 or 3 to remove them. See doc here for using different Realm through RealmConfiguration.
----------------------------------- Update for delete by Date field ------------------------------------------------------
For your user case, this would be a good choice:
Add a Date field to your model, and add annotation #Index to make query faster on it.
Update/add rows and set the modified date to current time.
Delete the objects where its modifiedDate is before the current date.realm.where(MyModel.class).lessThan("modifiedDate", currentDate).findAll().clear()
NOTE: "The dates are truncated with a precision of one second. In order to maintain compatibility between 32 bits and 64 bits devices, it is not possible to store dates before 1900-12-13 and after 2038-01-19." See current limitations. If you could modified the table in a very short time which the accuracy doesn't fit, consider to use a int field instead. You can get the column's max value by RealmResult.max()
this is more of a question of theory than anything else. I am writing an android app that uses a pre-packaged database. The purpose of the app is solely to search through this database and return values. Ill provide some abstract examples to illustrate my implementation and quandary. The user can search by: "Thing Name," and what I want returned to the user is values a, b, and c. I initially designed the database to have it all contained on a single sheet, and have column 1 be key_index, column 2 be name, column 3 be a, etc etc. When the user searches, the cursor will return the key_index, and then use that to pull values a b and c.
However, in my database "Thing alpha" can have a value a = 4 or a = 6. I do not want to repeat data in the database, i.e. have multiple rows with the same thing alpha, only separate "a" values. So what is the best way to organize the data given this situation? Do I keep all the "Thing Names" in a single sheet, and all the data separately. This is really a question of proper database design, which is definitely something foreign to me. Thanks for your help!
There's a thing called database normalization http://en.wikipedia.org/wiki/Database_normalization. You usually want to avoid redundancy and dependency in the DB entities using a corresponding design with surrogate keys and foreign keys and so on. Your "thing aplpha" looks like you want to have a many-to-many table like e.g. one or many songs belong/s to the same or different genres. You may want to create dictionary tables to hold your id,name pairs and have foreign keys referencing these tables. In your case it will be mostly a read-only DB so you might want to consider creating indexes with high FILLFACTOR percentage don't think sqlite allows it to do though. There're many ways to design the database. Everything depends on the purpose of DB. You can start with a design of your hardware like raids/file systems/db block sizes to match the F-System's block sizes in order to keep the I/O optimal and where to put your tablespaces/filegroups/indexes to balance the i/o load. The whole DB design theory/task is really a deep subject which is not to be underestimated nor is a matter of few sentences in the answer of stackoverflow. :)
without understanding your data better here is my guess at what you are looking for.
table: product
- _id
- name
table: attribute
- product_id
- a