Android External vs Internal Database Confusion

I am working on my first Android Application and I am trying to implement a database with a bunch of food types (strings) such as "Beef, Pork, Chicken" and have cook time values (int) for them such as 10000,50000,30000 etc. My question is what is the best way to implement this. I feel like the best way may be using an external database, but i am also thinking if it will make my life hell. Basically should I do something like an example I found that works off the internal SQlite:

public void onCreate(SQLiteDatabase db) {           
        db.execSQL("CREATE TABLE IF NOT EXISTS "
                +NAMES_TABLE
                +" (_id INT PRIMARY KEY ,name VARCHAR);"
        );

        db.execSQL("INSERT INTO "+NAMES_TABLE+" values(1,'marco');");
        db.execSQL("INSERT INTO "+NAMES_TABLE+" values(2,'luca');");
        db.execSQL("INSERT INTO "+NAMES_TABLE+" values(3,'qlimax');");

    }

This would add the values to the internal database when launched, only if they are not there. OR should I create a database with SQlitebrowser and place it in /assets and read from it?

Right now I am reading my values from an ArrayAdapter, and I am trying to replace it and read it from a database instead, it looks like this:

final FoodType type[] = new FoodType[3];
    type[0] = new FoodType("Filet Mignon",50000);
    type[1] = new FoodType("Skirt Steak",0);
    type[2] = new FoodType("Flank Steak",25000);
    ArrayAdapter<FoodType> typeAdapter = new ArrayAdapter<FoodType>(this,android.R.layout.simple_spinner_item,type);
    typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

How should I go about this? Internal or External?

Answers


In my personal experience, it depends on how big your database is and will be. For instance, the app I'm currently writing have tables with more than 50000 records, so it's better to copy an already created database to the assets directory.

On the other hand, if your database is simple enough... it's much better to populate it from the code (it will prevent some headaches, trust me).

With regards to your adapter... replace it with a SimpleCursorAdapter, it requires few changes in the constructor.


Need Your Help

Why does JSF + Tomahawk App produce records wih all null fields in MYSQL db

java jsf jpa tomahawk

The following works but when create button is hit is clicked it commits a record with all null filds

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.