The official Android developer website first mentions that we have to first ‘define a schema and contract’, which is something like this:
public static abstract class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_SUBTITLE = "subtitle";
...
}
The second step mentioned is to ‘Create a Database Using a SQL Helper’.
But all the tutorials I have seen on the web directly create a class using ‘helper’; For example. Which is the correct way? Both?
Also, should I define and create my database in the main Activity or create a separate Activity for the database?
Create database in SQLite browser (like SQLite Maestro), copy your database in assets folder in your project. Call
createDatabase()method in your MainActivity (which is first in your app, launcher activity).And helper class: