I am using three activities which are opened at the same time. All activities are retreive data from sqlite. I don't close or re open my connection when i am going from activity a->b or from b->c. I just dispose my db when activity is destroying.
Activity A
SqliteConnection db; OnCreate method db = new SqliteConnection(mypath); OnDestroy db.Dispose(); db=null; Onbuttonclick startActivity(new Intent(this, ActivityB)); Same code is running when i am going from activity b->c. Inside the same activity i use sqlite plenty of times.
Is this a good practice? Should i dispose my connection immediatelly after a use? Or should i close my connection on pause and reopen on resume? Or can i pass the same opened connection to the next activity? Which is the best approach?
Question modifieded
class databaseHelper { private static SqliteConnection db; public static SqliteConnection openDatabase(Context context) { if(db==null) db = new SqliteConnection(mypath); return db; } } And inside my activity on create
databaseHelper.openDatabase(this).myquery....