RandomGuy
RandomGuy

Reputation: 5219

Selecting a database for android

I was watching android tutorial on databases. They create a class and extend SQLiteOpenHelper. Then they would create a static final string for the database name. When you request a writable database it will always select using the static string. What is the convention used for selecting a different database? Just create another class and extend SQLiteOpenHelper? Also can you pass SQLiteDatabase from one activity to another using intent.putExtra or similar method?

Upvotes: 1

Views: 70

Answers (1)

K-ballo
K-ballo

Reputation: 81349

What is the convention used for selecting a different database?

The SQLiteOpenHelper handles more than just a database name. It handles schema version, creation, upgrades, etc... So I would expect the convention to be to define another class and extend SQLiteOpenHelper.

Can you pass SQLiteDatabase from one activity to another using intent.putExtra or similar method?

No, you can't. But you can create a new object of the class describing the database (that one that extends SQLiteOpenHelper, and request a database from it. Internally the SQLiteOpenHelper keeps a single writable connection to a database.

Upvotes: 2

Related Questions