I have the following class which is responsible to fetch non synced receipts from the receipts table and upload them to the server, the following function as of now just iterates through the cursor result set:
public class MidnightUpload {
public static void checkLocalAndUpload(final Context ctx) {
Cursor cursor = DatabaseHandler
.getInstance(ctx)
.getReadableDatabase()
.query(Receipt.TABLE_NAME, Receipt.FIELDS,
Receipt.WEB_RECEIPT_ID + " IS ?", new String[]{"dummy"},
null, null,
null, null);
if (cursor != null && cursor.moveToFirst()) {
do {
Log.d("_id", cursor.getString(cursor.getColumnIndexOrThrow("_id")));
Log.d("receipt_id", cursor.getString(cursor.getColumnIndexOrThrow("receipt_id")));
Log.d("web_receipt_id", cursor.getString(cursor.getColumnIndexOrThrow("web_receipt_id")));
Log.d("receipt_name", cursor.getString(cursor.getColumnIndexOrThrow("receipt_name")));
// Log.d("image", cursor.getString(cursor.getColumnIndexOrThrow("image")));
Log.d("date_added", cursor.getString(cursor.getColumnIndexOrThrow("date_added")));
Log.d("status", cursor.getString(cursor.getColumnIndexOrThrow("status")));
Log.d("currency", cursor.getString(cursor.getColumnIndexOrThrow("currency")));
Log.d("category", cursor.getString(cursor.getColumnIndexOrThrow("category")));
Log.d("sub_category", cursor.getString(cursor.getColumnIndexOrThrow("sub_category")));
Log.d("payment", cursor.getString(cursor.getColumnIndexOrThrow("payment")));
Log.d("invoice", cursor.getString(cursor.getColumnIndexOrThrow("invoice")));
Log.d("custom_field", cursor.getString(cursor.getColumnIndexOrThrow("custom_field")));
Log.d("organization", cursor.getString(cursor.getColumnIndexOrThrow("organization")));
Log.d("person", cursor.getString(cursor.getColumnIndexOrThrow("person")));
} while (cursor.moveToNext());
}
}
}
I am aware that I can start multiple Async Tasks using:
asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
The above method I am planning to call from an IntentService. So here are my confusions:
1) Will the do while loop wait till control has returned from asyncTask for the next iteration?
2)Will using and spawning multiple threads within an intentService disrupt my program?
3) Am I better off using Runnable r = new Runnable()
than AsyncTask - as I dont intend any UI operation?