Close DB
This commit is contained in:
parent
33567fe7d7
commit
62e2095a5a
@ -17,6 +17,7 @@ import android.util.Log;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import de.danoeh.antennapod.core.R;
|
import de.danoeh.antennapod.core.R;
|
||||||
import de.danoeh.antennapod.core.event.ProgressEvent;
|
import de.danoeh.antennapod.core.event.ProgressEvent;
|
||||||
@ -304,7 +305,7 @@ public class PodDBAdapter {
|
|||||||
private static SQLiteDatabase db;
|
private static SQLiteDatabase db;
|
||||||
private static Context context;
|
private static Context context;
|
||||||
private static PodDBHelper dbHelper;
|
private static PodDBHelper dbHelper;
|
||||||
private static int counter = 0;
|
private static AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
public static void init(Context context) {
|
public static void init(Context context) {
|
||||||
PodDBAdapter.context = context.getApplicationContext();
|
PodDBAdapter.context = context.getApplicationContext();
|
||||||
@ -319,9 +320,10 @@ public class PodDBAdapter {
|
|||||||
|
|
||||||
private PodDBAdapter() {}
|
private PodDBAdapter() {}
|
||||||
|
|
||||||
public PodDBAdapter open() {
|
public synchronized PodDBAdapter open() {
|
||||||
|
int adapters = counter.incrementAndGet();
|
||||||
|
Log.v(TAG, "Opening DB #" + adapters);
|
||||||
if (db == null || !db.isOpen() || db.isReadOnly()) {
|
if (db == null || !db.isOpen() || db.isReadOnly()) {
|
||||||
Log.v(TAG, "Opening DB");
|
|
||||||
try {
|
try {
|
||||||
db = dbHelper.getWritableDatabase();
|
db = dbHelper.getWritableDatabase();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
@ -335,8 +337,13 @@ public class PodDBAdapter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public synchronized void close() {
|
||||||
// do nothing
|
int adapters = counter.decrementAndGet();
|
||||||
|
Log.v(TAG, "Closing DB #" + adapters);
|
||||||
|
if(adapters == 0) {
|
||||||
|
Log.v(TAG, "Closing DB, really");
|
||||||
|
db.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteDatabase() {
|
public static boolean deleteDatabase() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user