Thursday, April 14, 2011

Revisiting ItemizedOverlay

I previously blogged on ArrayIndexOutOfBoundException when modifying ItemizedOverlay items on-the-fly, stating that they could be avoided. After much more use, I no longer believe ItemizedOverlay is safe for maps where content changes.

If you're developing an application that uses Google's Map API for Android and you need to add/remove items from the map while displaying the map, you have a few options:

1) "Allocate" all your objects in advance and disable items that should not be shown. This means you will not add/remove items to the ItemizedOverlay backing collection, but instead manage which ones are drawn in the draw() method. This may work well for many, but did not work for my scenario.

2) Create your own implementation of Overlay that handles concurrent modifications to its data structure. I chose this option, in particular because I didn't need all the capability that ItemizedOverlay offers.

3) Something else?

2 comments:

  1. Excellent post about android apps. A community for How Android Forum.This is the forum for help and discussion on Android Mobile Development, Galaxy, Nexus, Droid, HTC, IPhone, Media, Carriers, Games, Media, Development, Evo and all your favorites Android phones and tablets.
    Android Apps Development

    ReplyDelete