Skip to content

Instantly share code, notes, and snippets.

@easternHong
Created October 22, 2014 13:32
Show Gist options
  • Save easternHong/6109ffae4b0295495b04 to your computer and use it in GitHub Desktop.
Save easternHong/6109ffae4b0295495b04 to your computer and use it in GitHub Desktop.
SQLiteUtils_singleton_Pattern
public class SqliteUtils {
private static volatile SqliteUtils instance;
private DbHelper dbHelper;
private SQLiteDatabase db;
private SqliteUtils(Context context) {
dbHelper = new DbHelper(context);
db = dbHelper.getWritableDatabase();
}
public static SqliteUtils getInstance(Context context) {
if (instance == null) {
synchronized (SqliteUtils.class) {
if (instance == null) {
instance = new SqliteUtils(context);
}
}
}
return instance;
}
public SQLiteDatabase getDb() {
return db;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment