Created
October 22, 2014 13:32
-
-
Save easternHong/6109ffae4b0295495b04 to your computer and use it in GitHub Desktop.
SQLiteUtils_singleton_Pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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