0

I'm total beginner and I don't know how sql works inside android.

I'm having simple app game which needs database. During the game, app is displaying some records from database to users.

I have these questions:

1) does database and records still exists when user closes the app, and will the database and records still be available to the users?

2) code which creates database if it doesn't exists:

 SQLiteDatabase mydatabase = openOrCreateDatabase("tabu",MODE_PRIVATE,null);
    mydatabase.execSQL("CREATE TABLE IF NOT EXISTS rijeci(id INT, rijec VARCHAR, rijec1 VARCHAR, rijec2 VARCHAR, rijec3 VARCHAR, rijec4 VARCHAR);");

I put in the mail activity.java?

3) I want to insert some records into database which will be available o the users during the game (records will always be the same). My only idea is to insert values in database in main acitivty.java if they don't exist. But this does not seem like best solution because that code will be executed on every app start. Especially this will be bad solution if I need to insert large amount of data (something like 10000 records). What is better solution to insert records in database for once, before user even starts the app and never again?

1
  • Thanks for comment, I have removed tag. Commented Feb 8, 2015 at 22:12

1 Answer 1

1
  1. Yes the database exists even after the user closes the app. This database itself is a file stored somewhere on the phone, it's not tied to the process/activity that created it.

  2. Android uses sqlite and sqlite doesn't have the the VARCHAR data type, it only has NULL, INTEGER, BLOB, REAL and TEXT. Look at the sqlite.org website for more details in the data types. The android developer website actually has a pretty neat explanation of how the database works, and they provided the SQLiteOpenHelper class to help with basic database handling.

  3. If you're going to be inserting as many as 1000 entries, you should probably be using an AsyncTask for that, because that's a lot of work to do on the main thread. You could always just check if the number of entries in the table is the right amount and only proceed to delete the entries and insert the entries otherwise.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.