Hello, all.
How can I retrieve the current order ID that is open in the Register application on a specific device (from outside the Register Application)?
The code I used to implement the latest order retrieval is this:
cursor = MainActivity.this.getContentResolver().query(OrderContract.Summaries
.contentUriWithAccount(account), 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));
}
if (orderId == null) {
return orderConnector.createOrder(new Order());
} else {
return orderConnector.getOrder(orderId);
}
First impressions might make this seem like a good solution. The only problem is that this code it is not specific to a particular device. So, if an order is created on a separate device in the meantime, then it will choose that order ID instead of the one on the current device.
To elaborate further with an example:
Given two different end users using two different devices (device A and device B) tied to the same merchant account....
- An end user creates an order on device A.
- This end user starts adding items to that order.
- While this is happening, the end user on device B creates an order was well.
- The end user on device A now goes to my app, runs this code, and instead of retrieving the order ID from the order s/he was working on, instead, the ID is retrieved from the order that the user on device B created.
This scenario is what is occurring, and, logically, it makes sense because this snippet of code gets the 'last_modified' order ID, which would be the the order created on device B.
So my questions then are:
- Does anyone know of a method or implementation to retrieve the current order ID on the specific device (the one open in the Register Application)?
- OR can anyone think of a clever workout-around to this? (Maybe use a broadcast listener to intercept when an Order is created and go from there?)
Any help would be much appreciated! Thanks!