I had the code below minus the
In B4A I could get the size of the List but not access the maps, I got the error (see title)
After searching for info on the error I found THIS thread to help. I implemented the runOnUIThread, which is a method of Activity (so used ba.Activity in this case). Also Added the couple of bits of logging to see what is going on. I still get the 'DataChanged' log, but nothing else. indicating that it's simply not working right.
Running out of ideas again, so if anyone has any clues????
B4X:
mBA.activity.runOnUiThread(new Runnable() {
}
In B4A I could get the size of the List but not access the maps, I got the error (see title)
After searching for info on the error I found THIS thread to help. I implemented the runOnUIThread, which is a method of Activity (so used ba.Activity in this case). Also Added the couple of bits of logging to see what is going on. I still get the 'DataChanged' log, but nothing else. indicating that it's simply not working right.
B4X:
import anywheresoftware.b4a.objects.collections.List;
import anywheresoftware.b4a.objects.collections.Map;
....
....
@Override
public void onDataChanged(DataEventBuffer dataEvents) {
BA.Log("DataChanged");
final java.util.List<DataEvent> events = FreezableUtils.freezeIterable(dataEvents);
dataEvents.close();
mBA.activity.runOnUiThread(new Runnable() {
@Override
public void run(){
BA.Log("Inside Run");
if (mBA.subExists(mEventname + "_datachanged")) {
//Get the data
List Items = new List();
List DeletedItems = new List();
Items.Initialize();
DeletedItems.Initialize();
for (DataEvent event : events) {
if (event.getType() == DataEvent.TYPE_CHANGED) {
Map Item = new Map();
Item.Initialize();
DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
Item.Put(dataMapItem.getUri().getPath(), dataMapItem.getDataMap()) ;
Items.Add(Item.getObject());
} else if (event.getType() == DataEvent.TYPE_DELETED) {
Map Item = new Map();
Item.Initialize();
DataMapItem dataMapItem = DataMapItem.fromDataItem(event.getDataItem());
Item.Put(dataMapItem.getUri().getPath(), dataMapItem.getDataMap());
DeletedItems.Add(Item.getObject());
}
}
BA.Log("Raising Event");
mBA.raiseEvent(mGoogleApiClient, mEventname + "_datachanged", new Object[] {Items, DeletedItems});
}
}
});
}
Running out of ideas again, so if anyone has any clues????