Log.d(TAG, "Running selection: " + selection);
}
- Cursor c = null;
- try {
- c = mMusicDatabase.getReadableDatabase().rawQuery(selection, null);
-
+ try (Cursor c = mMusicDatabase.getReadableDatabase().rawQuery(selection, null)) {
if (c != null && c.moveToFirst()) {
sortData.ids = new long[c.getCount()];
- sortData.bucketLabels = new ArrayList<String>(c.getCount());
+ sortData.bucketLabels = new ArrayList<>(c.getCount());
do {
sortData.ids[c.getPosition()] = c.getLong(0);
sortData.bucketLabels.add(c.getString(1));
} while (c.moveToNext());
}
- } finally {
- if (c != null) {
- c.close();
- }
}
return sortData;