android - Should the context of SQLiteOpenHelper always be the running activity? -
i want open database
once main screen of app , , want use instance anywhere in activity
. possible or should make context
each actual opened activity
must create instance of database ( open ) in every activity
?
is possible or should make context each actual opened activity must create instance of database ( open ) in every activity ?
it possible, , use application context. dbhelper
singleton. e.g
public class dbhelper extends sqliteopenhelper { private static dbhelper sinstance; public static synchronized dbhelper getinstance(context context) { if (sinstance == null) { sinstance = new dbhelper(context.getapplicationcontext()); } return sinstance; } private dbhelper(context context) { super(context, database_name, null, database_version); } }
Comments
Post a Comment