Android applications that use the MyLocationOverlay class crash on the new Droid X


Update: August 29, 2010
Tested this myself on a friend’s phone and this bug is definitively not fixed yet despite the recent Motorola updates! The burden is on you (the developer) to fix this if you want your applications to run on a Droid X.
Update: August 23, 2010
Still getting reports that the update issued by Motorola last month did not fix this issue!


As soon as the new Motorola Droid X came out I started getting reports that my applications would crash on it.

The description I was getting from people was that the application would start, then it would show the Google map and start moving the map and zooming in on to their current location and then all of a sudden the app would crash. By crash I mean they get taken back to the phone’s home screen. No “Force Close” dialog pops up… nothing… just gets back to the home screen.

If both the GPS and the Wireless Networks are turned off from the Locations settings then the applications would work fine, but of course that means that the current location of the device would be impossible to find.

At this point I knew that the problem had to do with either the LocationManagers or the LocationOverlays but I had no way of finding out exactly what the problem was until I could get my hands on a Droid X phone and connect it to my computer to look at the execution stack.

Well it turns out the problem is with the default MyLocationOverlay class. The Droid X phones throw an exception when they try to draw the dot showing the location of the device:

E/AndroidRuntime(10458): Uncaught handler: thread main exiting due to  uncaught exception
E/AndroidRuntime(10458): java.lang.ClassCastException:  android.graphics.drawable.BitmapDrawable
E/AndroidRuntime(10458): 	at com.google.android.maps.MyLocationOverlay.getLocationDot(MyLocationOverlay.java:180)
E/AndroidRuntime(10458): 	at com.google.android.maps.MyLocationOverlay.drawMyLocation(MyLocationOverlay.java:561)

Another developer (rgfindl) who had the same problem like I did and who had already made the trip to the Verizon store gave me the above stack trace.

Several possible solutions popped into my head:

1. Stop using the MyLocationOverlay class and start relying only on the LocationManager classes and draw/redraw my current location onLocationChanged.
2. Extend from MyLocationOverlay class and override the draw method.
3. Stop supporting the Droid X.

None of these solutions are ideal with the last one being almost unacceptable.

Luckily the same developer also gave me a link to a solution implementing the 2nd option above, so I did not even have to code it myself. Apparently that is not the first time Motorola phones (Motorola Cliq and Motorola Dext) have a problem with this class. Most likely their builds are missing the drawable resource.

Anyway, the solution consists of the .java file that implements the FixedMyLocationOverlay class, which inherits from the default MyLocationOverlay class and overrides the drawMyLocation method. And a .png file with a dot that will be representing the current location on the map.

Just use this derived class FixedMyLocationOverlay instead of the default MyLocationOverlay. If you look at the implementation of the drawMyLocation method, you will see that if the phone has no problem it will use the default implementation of the parent class, but if it throws an exception it will use the custom code to draw the location.

I would think that there are a lot of applications in the Android Market right now that use the default MyLocationOverlay class and all of them will be crashing on the new Droid X until either Motorola gets their act together or the developers realize the issue and work around it.

Monday, July 19th, 2010 Android, Eclipse, Java, Programming

14 Comments to Android applications that use the MyLocationOverlay class crash on the new Droid X

  1. My application suffers the same problem on Droid X. It works fine on the original Droid. Custom Android ROM sucks. Thanks for the information.

  2. myzuku on August 4th, 2010
  3. I’ve seen this issue in my own application, Todo Q. Trying your fix now. Thanks for the information.

  4. billybobbain on August 5th, 2010
  5. Apparently the Droid X with the latest update still has the MyLocationOverlay bug as of Aug 23, 2010.

  6. kickingvegas on August 23rd, 2010
  7. @kickingvegas,

    Thank you for the update!

  8. dimitar on August 23rd, 2010
  9. My app has been suffering this problem for a long time.
    But, it all fine now.
    Thank you very much for your information!!

  10. Yoshi on August 24th, 2010
  11. Wow, thank you for the short blurb about this issue. I could not for the life of me determine what was causing this on my own Android device until stumbling across this post. Once I made the appropriate changes and extended my own MyLocationProvider, all was well. Thank you again!

  12. SteveO on September 7th, 2010
  13. Thanks a lot! FixedMyLocationOverlay resolves the problem.

  14. maranoid on September 14th, 2010
  15. Just got a hold of a Droid X to try and fix this problem. Searched on the error message. Love the internet. Thanks.

  16. Randy on September 16th, 2010
  17. Thanks a lot for the info and for the solution!

    Regards,
    Dennis R.

  18. Dennis R. on December 10th, 2010
  19. [...] is another, similar problem with a missing image on google maps, which is easy enough to solve and documented elsewhere as being on Droid phones as well. [...]

  20. google maps glitch on motorola phones - Question Lounge on January 4th, 2011
  21. Thanks a lot for providing useful solution

  22. Menghan Li on January 21st, 2011
  23. Thanks for your code.

    One more thing, if like me you don’t want to use a drawable that is just use in the Droid X case, just paint it on the drawable like this :

    float fDensity = mapView.getContext().getResources().getDisplayMetrics().density;
    int iBuggedMyLocationBitmapSize = (int) (20 * fDensity);

    Bitmap oBuggedMyLocationBitmap = Bitmap.createBitmap(iBuggedMyLocationBitmapSize, iBuggedMyLocationBitmapSize, Bitmap.Config.ARGB_4444);
    Canvas oBuggedMyLocationCanvas = new Canvas(oBuggedMyLocationBitmap);

    Paint oPointPaint = new Paint(); oPointPaint.setAntiAlias(true);

    oPointPaint.setColor(0xff292c29);
    oPointPaint.setStyle(Style.FILL);
    oBuggedMyLocationCanvas.drawCircle(iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize * 10 / 2, oPointPaint);

    oPointPaint.setColor(0xffe7e7e7);
    oPointPaint.setStyle(Style.FILL);
    oBuggedMyLocationCanvas.drawCircle(iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize * 8 / 20, oPointPaint);

    oPointPaint.setColor(0xff10b2d6);
    oPointPaint.setStyle(Style.FILL);
    oBuggedMyLocationCanvas.drawCircle(iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize * 5 / 20, oPointPaint);

    this.drawable = new BitmapDrawable(oBuggedMyLocationBitmap);

  24. Thomas on October 27th, 2011
  25. Sorry, just made an error on the first circle paint :
    oBuggedMyLocationCanvas.drawCircle(iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize / 2, iBuggedMyLocationBitmapSize * 10 / 20, oPointPaint);

  26. Thomas on October 27th, 2011
  27. [...] I returned to the issue, I found an article by Dimitar Darazhanski which perfectly described the issue that I was up against. As it turns out, when Motorola [...]

  28. Droid X Cannot Find Position With The MyLocationOverlay Class | MostlyBinary on March 11th, 2012

Leave a comment

*

Search

 

Archive

September 2014
M T W T F S S
« Jul    
1234567
891011121314
15161718192021
22232425262728
2930  

Other