android - How do I handle my database within one class and securely close it in the end? -
android - How do I handle my database within one class and securely close it in the end? -
i have class database access. holds reference sqlitedatabase. 30 or functions this:
public boolean updatesomething(long a, int b, long c) { contentvalues values = new contentvalues(); values.put(col_a, a); ... homecoming database.update(table, values, col_id + "=?", new string[]{id}) > 0; } many stackoverflows suggest this:
public boolean updatesomething(long a, int b, long c) { sqlitedatabase database = dbhelper.getwritabledatabase(); contentvalues values = new contentvalues(); values.put(col_a, a); ... boolean success = database.update(table, values, col_id + "=?", new string[]{id}) > 0; database.close(); homecoming success; } but have functions homecoming cursors exactly because need cursor on 10k rows of database , can't re-create stuff array , close database.
others open database in onresume , close onpause means move database code activities or have database parameter in these functions. 1 time again do asynctasks , other classes run in parallel activities.
my approach open database in main activity , close on destroy, realized might created multiple times counted instances. realized might destroyed while activity relies on having database , that's i'm stuck now. application has no onstart/stop callbacks utilize connect , close database in.
in android: how close cursor returns class activity suggested not bother closing database. wise move? mean that's how started , logcat got me worry , described above. downwards side of never closing database other log output?
how static singleton db access class handles database jobs. can phone call static method on destroy (or when ever appropriate) close connection.?
android database sqlite cursor
Comments
Post a Comment