Issue
Very (very) basic question that unclear to me: Is SQLite db remain after application shutdown with all the data that was added to it or destroyed?
If so (and I hope so), when is the the DB schema created during the app lifecycle? I would expect it to be created on app installation, but according to the documentation I see this is done every time that the application started.
What am I missing? When is the code below executed during the application life cycle?
public class DatabaseHandler extends SQLiteOpenHelper {
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_PH_NO + " TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
} //DatabaseHandler
Solution
the DB data is stored under /data/data/<your.app.package.name>/database/
(or something similar to that). It is a physical file that remains stored on the device until your application is uninstalled or the user goes to Settings->App->Clear Data
the code you posted is executed the first time ever your app executes getReadableDatabase
or getWritableDatabase
. That means, the SQLiteOpenHelper
class checks if a valid DB file exist on that location in disk. If there's no file, it executes the onCreate
(which creates the DB file).
excerpt from methods getReadableDatabase
or getWritableDatabase
documentation:
Create and/or open a database
Answered By - Budius
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.