//Async Task which fetches the current order
public class FetchOrder extends AsyncTask<Void, Void, Order> { @Override protected Order doInBackground(Void... voids) { Cursor cursor = null; String orderId = null;
//Initialize OrderConnector OrderConnector mOrderConnector = new OrderConnector(getApplicationContext(), CloverAccount.getAccount(getApplicationContext()), null); mOrderConnector.connect(); try { // Query the last order cursor = getApplicationContext().getContentResolver().query(OrderContract.Summaries.contentUriWithAccount(mAccount), new String[]{OrderContract.Summaries.ID}, null, null, OrderContract.Summaries.LAST_MODIFIED + " DESC LIMIT 1"); if (cursor != null && cursor.moveToFirst()) { orderId = cursor.getString(cursor.getColumnIndex(OrderContract.Summaries.ID)); } // return Order if most recent order is found if (orderId == "") { Log.d(TAG, "Unable to fetch order"); } else { return mOrderConnector.getOrder(orderId); } } catch (RemoteException | ClientException | ServiceException | BindingException e) { e.printStackTrace(); } finally { mOrderConnector.disconnect(); } return null; } }
1 Person is following this question.