Back to project page Abstract-Model.
The source code is released under:
Apache License
If you think the Android project Abstract-Model listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.logician.abstractModel.examples; /*from w w w . j a va 2s. c om*/ import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public final class MyDatabaseOpenHelper extends SQLiteOpenHelper { private static final String NAME = "mydatabase"; private static final int VERSION = 3; // To avoid concurrency issues, you should use the singleton model. // See this blog post about the issue: // http://www.androiddesignpatterns.com/2012/05/correctly-managing-your-sqlite-database.html private static MyDatabaseOpenHelper singleton = null; private MyDatabaseOpenHelper(Context context) { super(context, NAME, null, VERSION); } public static MyDatabaseOpenHelper getInstance(Context context){ if(singleton == null) /** * It is best to use the Application context so * you don't accidentally leak the context * of an Activity or Service. */ singleton = new MyDatabaseOpenHelper(context.getApplicationContext()); return singleton; } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(new User().getTableSQL()); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }