I am trying to pass an ArrayList from an IntentService to an activity running on the main UI thread. I have implemented broadcasts and onRecieve() without any problems for broadcasting a single Location object. Location (A google API class) does implement parcelable, and I don't believe there are any issues with the class as using putParcelableExtra() works fine. However, when I try to use putParcelableArrayListExtra(ArrayList), I end up receiving an empty ArrayList. I get no exceptions, no errors, nothing. But the ArrayList.tostring() just shows []. I have logged the array list before broadcasting and it shows a number of Location objects, so I know it is populated. Here is the main code:
In broadcast in IntentService:
private void broadcastLocationList(ArrayList<Location> locationList) {
Log.d(LOG_TAG, "broadcast location list");
Log.d(LOG_TAG, locationList.toString());
Intent intent = new Intent(BROADCAST_NEW_LOCATION);
intent.putExtra(BROADCAST_TYPE, LIST_TYPE);
intent.putParcelableArrayListExtra(SERVICE_LOCATION_UPDATE, locationList);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
In the receiving activity:
if (intent.getAction().equals(GPSIntentService.BROADCAST_NEW_LOCATION)) {
if (intent.getIntExtra(GPSIntentService.BROADCAST_TYPE, GPSIntentService.SINGLE_TYPE) == GPSIntentService.LIST_TYPE) {
ArrayList<Location> locList = new ArrayList<Location>();
locList = intent.getParcelableArrayListExtra(GPSIntentService.SERVICE_LOCATION_UPDATE);
Log.d(LOG_TAG, locList.toString());
addPointsFromArrayList(locList);
Log.d(LOG_TAG, "onRecieve() gps list");
}
I know that the broadcast is occurring and being received because the logs within the second code block are running, But the output I get from
Log.d(LOG_TAG, locList.toString());
is just []. This is very different from the log on the broadcast end, which looks like:
[Location[fused 39.754756,-105.004355 hAcc=17 et=+1d14h5m26s327ms alt=1576.5999755859375 vel=0.28307897 bear=212.75104 vAcc=7 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}], Location[fused 39.754758,-105.004363 hAcc=17 et=+1d14h5m31s298ms alt=1576.7999267578125 vel=0.1378234 bear=253.65567 vAcc=7 sAcc=??? bAcc=??? {Bundle[mParcelledData.dataSize=52]}]]
I've tried creating a Bundle and then putting the array list extra in the bundle and putting the bundle in the intent, but there is no difference. I've also tried changing around the ways that I initialize locList from the parcelableArrayListExtra, but nothing works. Any ideas?
UPDATE:
For people having a similar issue, I just ended up broadcasting individual locations one by one, and this approach works well enough. Still would like to know what was wrong with the list issue though.