Don't retrieve the column index again and again in a long loop
Also: fix weird iteration logic
This commit is contained in:
parent
2da50e27c2
commit
87023ebdb3
|
@ -221,17 +221,20 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
|||
try (SQLiteDatabase db = this.getReadableDatabase()) {
|
||||
try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order)) {
|
||||
LOG.info("Activity query result: " + cursor.getCount() + " samples");
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
GBActivitySample sample = new GBActivitySample(
|
||||
provider,
|
||||
cursor.getInt(cursor.getColumnIndex(KEY_TIMESTAMP)),
|
||||
cursor.getInt(cursor.getColumnIndex(KEY_INTENSITY)),
|
||||
cursor.getInt(cursor.getColumnIndex(KEY_STEPS)),
|
||||
cursor.getInt(cursor.getColumnIndex(KEY_TYPE)),
|
||||
cursor.getInt(cursor.getColumnIndex(KEY_CUSTOM_SHORT)));
|
||||
samples.add(sample);
|
||||
} while (cursor.moveToNext());
|
||||
int colTimeStamp = cursor.getColumnIndex(KEY_TIMESTAMP);
|
||||
int colIntensity = cursor.getColumnIndex(KEY_INTENSITY);
|
||||
int colSteps = cursor.getColumnIndex(KEY_STEPS);
|
||||
int colType = cursor.getColumnIndex(KEY_TYPE);
|
||||
int colCustomShort = cursor.getColumnIndex(KEY_CUSTOM_SHORT);
|
||||
while (cursor.moveToFirst()) {
|
||||
GBActivitySample sample = new GBActivitySample(
|
||||
provider,
|
||||
cursor.getInt(colTimeStamp),
|
||||
cursor.getInt(colIntensity),
|
||||
cursor.getInt(colSteps),
|
||||
cursor.getInt(colType),
|
||||
cursor.getInt(colCustomShort));
|
||||
samples.add(sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,8 +67,7 @@ public class K9Receiver extends BroadcastReceiver {
|
|||
|
||||
try {
|
||||
if (c != null) {
|
||||
c.moveToFirst();
|
||||
do {
|
||||
while (c.moveToFirst()) {
|
||||
String uri = c.getString(c.getColumnIndex("uri"));
|
||||
if (uri.equals(uriWanted)) {
|
||||
notificationSpec.sender = c.getString(c.getColumnIndex("senderAddress"));
|
||||
|
@ -76,7 +75,7 @@ public class K9Receiver extends BroadcastReceiver {
|
|||
notificationSpec.body = c.getString(c.getColumnIndex("preview"));
|
||||
break;
|
||||
}
|
||||
} while (c.moveToNext());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (c != null) {
|
||||
|
|
Loading…
Reference in New Issue