android quiz game method selection - android

I am new to android and i want to build a quiz game for practice. I thought of creating question packages, each containing up to 1000 questions which the players will be able to download. I am thinking to insert the questions in a database (SQlite database) so each time I get a random number from 1 to 1000 for example i ll just use a query to search for the question with that id.
Some friends told me I should use xml files for the questions cause it would be easier to download the packages to each players device. But wouldnt that force me to search for the question with the right id in the entire xml and thus take alot more time than simply asking for a record with a specific id from a database?
Other consern is the communication with my server. What i m trying to say is, i read i should be using a a RESTful service but here is my question. I know that its easy to download an app from the store and view its source code. So whats stopping the guy who does that from seeing my database credentials inside the apps code and being able to have access to my remote server where all my clients data will be stored?
I am sorry if my questions are confusing but i just need some guidlines from where to begin...
thanks in advance

You're mixing up two questions here:
How to store the questions on the server
How to transfer them to the device.
SQL is a good choice for the server side, you'll need to come up with some possibility to insert questions to your database, you'll probably not want to insert them with manual SQL statements. You can for example create a small Java applet that let's you insert them.
XML or JSON via a REST api seem to be the options that make the most sense. Serializing and deserializing them with SimpleXML or Gson is easy-peasy.
On how to secure your app/game against people just downloading all of your questions (and probably answers), can't really tell. I would guess that 'serious' quiz games use some forms of encryption and authentication there.

Related

How to store Data for my application

I'm really new to programming apps - so this question might sound a bit strange:
I'm trying to program an app in android studio, where people can upload different things (basically strings and links put together in some kind of "package") and other peoble can then decide what "packages" they want to add inside their app. However after downloading, this data should be stored on their device and not just in the memory of the phone so that they can use it after restarting the app (and also if theres no internet connection). Do you have any idea what would be the best way to store this data both on the phone and in a database and how to synchronize the data on the phone with the selected data from the database. I really dont want to know how to do this exactly but would rather like some basic ideas and maybe you could tell me what kinds of stuff i should learn in order to succeed and what kind of database would be best here (firebase, MYSQL,..)?
Thanks a lot,
Andi
First of all you should decide what DB you are going to use.
In my opinion all RDBMs are good, but using Sqlite in order to achieve best performance on android devices is a good idea.
In your case you need server-side DB and application too.
(Depend on the scenario and framework you use can be different (sql,mysql,PostgreSQL,oracle,...)).
About how to sync local database with server-side you can download new DB from server and replace it with previous one, if you need previous user data you can have 2 different table and update one by downloading it from server, and save id or any identical row from specific package that already saved by user.
These are some question has been already answered in Stackoverflow
java - How to update table in sqlite?
java - SQLite in Android How to update a specific row
Create SQLite database in android
If you are talking about local databases. Go for Realm or look up a good ORM on github (Object relational mapping, you dont have to write SQL queries explicitly) .
I would suggest Realm which is very fast and user friendly.

Best Database design option for Android application with huge data

I am new to Android Application Development and a new member at stackoverflow. I am currently trying to design a recipe application. I have decided upon the features of the app and the scope it will cover. The scope is very vast for me in terms of covering all the recipes from all over the world. I am to deal with a lot of data in this process.
I am currently trying to figure a good and efficient way of handling the data in my app. So far, as per what I have read in different forums, I believe that I have two options in terms of a database choice : 1) SQLite 2) Database on remote server (MySql/Postgre)
Following are some of the thoughts that have been going on in my mind when it comes to taking a decision between the two :
1) SQLite : This could be a good option but would be slow as it would need to access the file system. I could eliminate the slowness by performing DB data fetch tasks in the AsyncTask. But then there could be a limitation of the storage on different phones. Also I believe using SQLite would be easier as compared to using a remote DB.
2) Remote Database : The issue that I can see here is the slowness with multiple DB requests coming at the same time. Can I use threads here in some way to queue multiple requests and handle them one by one ? Is there an efficient way to do this.
Also I have one more question in terms of the formatting of my data once I pull it out from the above DB's. Is there a way I could preserve the formatting of my data ?
I would be more than thankful if someone could share their knowledgeable and expert comments on the above scenario. Also this is not a homework for me and I am not looking for any ready made code solutions. I am just looking for hints/suggestions that would help me clear my thoughts and help me take a decision. I have been looking for this for sometime now but was not able to find concrete information. I hope I will get some good advice here from the experienced people who might have encountered similar situation.
Thanks for reading this long post.
What about combining both approaches?
A local SQLite database that has the least recently used receipes so you don't need network all the time. Network is way slower than accessing the filesystem.
Some remote database accessed via some HTTP interface where you can read / write the whole database. And if you want users to be able to add receipes for other users to see you'll need an external database anyways.
SQLite : This could be a good option but would be slow as it would need to access the file system.
Accessing a local database is pretty fast, 5ms or so if it's just a simple read only query on a small database.
But then there could be a limitation of the storage on different phones
Depends on your definition of huge database. It is okay if it is only 2MB which would be enough to store lots of text-only receipes.
Also I believe using SQLite would be easier as compared to using a remote DB.
Yes, Android has a nice built-in SQLite API but no remote database API. And you don't need to setup a database server & interface.
The issue that I can see here is the slowness with multiple DB requests coming at the same time.
A decent database server can handle thousands of requests. Depends on your server hardware & software. https://dba.stackexchange.com/ should have more info on that. Required performance depends on how much users you have / expect.
I'd suggest a simple REST interface to your database since it's pretty lightweight but does not expose your database directly to the web. There are tons of tutorials and books about creating such interfaces to databases. There are even hosted database services like nextDb that do most of the work for you.
Is there a way I could preserve the formatting of my data ?
You could store HTML formatted data in your database and display it in a WebView or a TextView (via Html#fromHtml()) - both can display formatted text.
Databases don't care what type of text you store, for transfer over the internets you may need to encode the text so it does not interfere with the transport formatting (XML, JSON, ...).
A simple way is to integrate Parse into your app. They have a nice framework that easily integrates into iOS and Android. Their plan is freemium, so you'll be able to use up to 1 million API request for no charge, and then its 7 cents for every request after that.
You'll have 1gb to store all your data sets / images, etc.
I don't use parse for everything, but I HIGHLY recommended it for large data schemes because they do all the scaling for you. Check out the API, I think it would be worth your time.
I just started to work on a few of my own projects, and I'm using Parse again. I have to say it's improved a lot over the last 6-8 months. Especially with the Twitter and Facebook integration.
The key issue here is the size of the data - any significant database of recipes would be too large to store on the phone imho,thus you seem stuck with the remote database solution.
As opposed to trying access the remote database from android I suggest you use a a go between web application that will process requests from the application and return JSON objects that you need.
It totally depends on your software requirements. If you need to deal with a small amount of data then you may choose SQLite, but for a huge amount to data better use a remote DB.
SQLite: It works fine with little amount of data & I experienced it response time is good.
Remote DB: I think you may use small server side app to submit the data to your client app. It will solve/reduce your thread related issues/complexities.

Using Rest to store data in Sqlite

I'm creating my first android app that will make use of SQlite. I have zero experience with databases, except for creating a mysql database to use with wordpress...
Edit: After doing some research about rest, I'm still confused about how rest, sqlite, and android dev fit together. My goal is to access a rest-based web service through a url and access certain datasets, then store them in my SQlite database. Then I want to access the contents of the database through my java program, and use them accordingly.
The datasets can be downloaded individually in CSV format, but because I will be using so many of them, I don't want to go through every line individually and store them in the database. I'm hoping there's a more efficient way to store these datasets in the database.
My main questions are:
How can I copy the XML contents of a webpage from a url into my sqlite database? Can I do this with my java program, through the sqlite database, or a java library?
Do I only need to copy the contents of the webpages from the url into the sqlite database one time? If so, what can I do if any information is changed in the datasets?
You first need a schema for your sqllite DB. That schema should map to the objects behind the web service. For e.g, you need a Person table in your DB if there is a Person entity on the web. It depends on what all you want to capture.
When you are done designing the schema, you should start writing the code that help you create & manage DB on android. This is done with the help of SQLiteOpenHelper class:
http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html
If you need to keep the DB synce'd with the data on the cloud (web services), you should implement sync. Android provides a very efficient sync framework.
Also, do watch this video from Android engineers explaining the best practices: http://www.youtube.com/watch?v=xHXn3Kg2IQE
Note, to actually fetch the data from the web service you would use UrlConnection API:
http://developer.android.com/reference/java/net/URLConnection.html
This sample probably captures most of it.
http://developer.android.com/resources/samples/SampleSyncAdapter/index.html
In terms of reading CSV files, there are some good resources here:
Can you recommend a Java library for reading (and possibly writing) CSV files?
Once you have read each CSV line into an object, then you can turn around and persist it to the database. I'm the author of ORMLite so I'll talk about using it. I don't believe there is a hibernate port for Android.
There are a number of Android examples to help you to get up to speed with ORMLite. Also some good tutorials. If you want to write a number of rows at once then I'd recommend using the batch tasks ORMLite feature. For information, see the discussion about creating lists of objects on the mailing list.
I can answer your first question about " I'm not sure how to add them efficiently"?
yes, SQlite is very powerful and intelligent, you can add thousand of records in one transaction, just like traditional database, It significantly improve performance.
about second question, as my understanding, because CVS file is very simple, so you can download and analyze it by yourself.

Help getting started with SQL database on Android?

I have zero experience with databases, and am looking for some direction in getting started. I am making an Android app that needs to read in a large amount of data quickly... Eventually this will be a stock market app that accesses real-time stock information. But before I spend money trying to get access to such real-time data, I'm working with a Microsoft excel file that has times and information on stocks from the past.
I've read up on databases and apparently Androids come with SQLite but I can't figure out how to start using it, or how to import my excel file.
Please help get me started or point me in the right direction. I've found some tutorials but they were difficult for me to follow with my complete lack of experience, and not necessarily related to my project; I'd need really basic step-by-step instructions...
Here is one way of doing this, think only in terms of data you need, rather than trying to get all spreadsheet data into your SQLite DB.
So, think in terms of learning basic SQL and SQL queries and create the tables (on a piece of paper) you need, how you will manipulate the data in these tables (updates, inserts, deletes etc).
Now that you have the table schema and your queries, the task remains of importing this data into the tables. For this I haven't done this but I am sure you will find a lot of resources on the Internet.
Now, as you can see, the seemingly complicated problem is broken into tangible actionable steps.
Here is a reasonable tutorial on SQLite. Here is another for SQLite and Android. You can google for more help.
Also take a look here. The blog talks about importing from excel into SQLite DB.

Which is better, using a SQLite database or hardcoding data into a function?

I'm working on a trivia like app and wondering how is the best way to store all of the questions and answers. Right now, I just have a random number and using a whole lot of if statements. For example, if randomNum = 25, then question is THIS and choices are THIS. This seems to work fine, but my file is starting to get very large and this seems like it should cause performance issues. Space is also starting to become an issue. I have started to look into just putting all of the data into database and use a random number to just retrieve a row. Anybody have any suggestions on which would be the best practice or have any other ways of doing this?
Sounds like its a good time to start using the database. You can learn how to include a pre-populated database here.
...using a whole lot of if statements.
I have started to look into just putting all of the data into database and use a random number to just retrieve a row
I think you've kinda answered the question yourself.
What happens with your model if you have 10,000 questions? Are you going to use 10,000 'if' statements?
Even if you're never going to get to that many questions, using a SELECT on a DB where the question number equals a particular random number, is going to be far more extensible.
You should use the database.
It's not just a maintainability and (ultimately) a code simplicity option, either, but offers significant advantages.
Imagine if you want to be able to supply different packs of questions, for example. You could offer people the ability to download a trivia pack from a website, or load it from a file off their SDcard. This simply would not work for masses of if statements.
Suppose you want to let people add their own trivia questions? Upload them to the website for voting and ultimate inclusion into crowd-sourced question packs.
So yeah: you should use a database.

Categories

Resources