Painfully slow with > 5 overlay items

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Painfully slow with > 5 overlay items

Postby R*BOMB » Thu May 06, 2010 11:52 pm

Hi,
I am writing a simple GPS app that will plot the points and draw the path of wherever you go... however once more than 5 points are drawn onto the map and the associated path is drawn the app becomes more or less unusable as it nearly locks up completely... which really is not fun. I believe i know what the problem is but i am unsure how i would... solve the issue. As it stands I only update the coordinates and what not when the application resumes, meaning i only really need to draw the items once... at least i hope so. I Override the onDraw() method in Itemized Overlay, in hopes that that would only be called once, however it appears it is called every time anything changes on the UI....

Is there anyway i can avoid this lag from happening, or prevent onDraw from being called, or anything which would solve my issues? : /

Thank you in advance

R*BOMB
R*BOMB
Freshman
Freshman
 
Posts: 3
Joined: Thu May 06, 2010 11:44 pm

Top

Postby kekomal » Fri May 07, 2010 7:42 am

mmm, that's not normal. Which device are you using? Perhaps there is some kind of problem in your code that affects the performance. Are you sure that you sure that you have only added one Overlay per point? Are you sure there is no unnecessary calls to invalidate() method?

Related parts of the source code would be helpful.

Apart of this, I think that, for your purpose, is enough extending Overlay (there is no need to extend ItemizedOverlay), but I am sure that's not the problem.
kekomal
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Mar 17, 2010 10:44 am
Location: Bilbao, Spain

Postby R*BOMB » Fri May 07, 2010 10:41 pm

The device is both my milestone and the emulator, both seem to have the same effect. Also i never call invalidate() on my own. And i am positive that there is only one overlay per point. Apart from those comments... I am still at a complete standstill.

I will PM you the entire class, if you don't mind.



EDIT: It appears the draw() is in a near infinite loop (loop seems to break after 5 mins, then starts again as soon as something happens) from some unknown source...

Thread [<3> main] (Suspended (breakpoint at line 257 in MainActivity$LocItemizedOverlay))
MainActivity$LocItemizedOverlay.draw(Canvas, MapView, boolean) line: 257
MainActivity$LocItemizedOverlay(Overlay).draw(Canvas, MapView, boolean, long) line: 179
OverlayBundle.draw(Canvas, MapView, long) line: 42
MapView.onDraw(Canvas) line: 476
MapView(View).draw(Canvas) line: 6536
RelativeLayout(ViewGroup).drawChild(Canvas, View, long) line: 1527
RelativeLayout(ViewGroup).dispatchDraw(Canvas) line: 1257
FrameLayout(ViewGroup).drawChild(Canvas, View, long) line: 1525
FrameLayout(ViewGroup).dispatchDraw(Canvas) line: 1257
FrameLayout(View).draw(Canvas) line: 6539
FrameLayout.draw(Canvas) line: 352
LinearLayout(ViewGroup).drawChild(Canvas, View, long) line: 1527
LinearLayout(ViewGroup).dispatchDraw(Canvas) line: 1257
PhoneWindow$DecorView(ViewGroup).drawChild(Canvas, View, long) line: 1525
PhoneWindow$DecorView(ViewGroup).dispatchDraw(Canvas) line: 1257
PhoneWindow$DecorView(View).draw(Canvas) line: 6539
PhoneWindow$DecorView(FrameLayout).draw(Canvas) line: 352
PhoneWindow$DecorView.draw(Canvas) line: 1830
ViewRoot.draw(boolean) line: 1349
ViewRoot.performTraversals() line: 1114
ViewRoot.handleMessage(Message) line: 1633
ViewRoot(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 123
ActivityThread.main(String[]) line: 4338
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 521
ZygoteInit$MethodAndArgsCaller.run() line: 860
ZygoteInit.main(String[]) line: 618
NativeStart.main(String[]) line: not available [native method]
R*BOMB
Freshman
Freshman
 
Posts: 3
Joined: Thu May 06, 2010 11:44 pm

Postby kekomal » Mon May 10, 2010 8:59 am

Hi R*BOMB,

I have taken a quick look to your code. I'm not totally sure, but I see some problems in plotPoints method:

1. mapOverlays.add(itemizedOverlay) is called inside the loop. This way, for 5 OverlayItems, you have the same ItemizedOverlay with the same 5 OverlayItems referenced 5 times. Take this call out of the loop.


2. plotPoints is called every onResume. Of course, you are clearing itemizedOverlay, but after refilling it, you are adding it again to mapOverlays; so every time onResume is called (when returning from SettingsActivity or from a phone call, for instance) you add new references for itemizedOverlay. Consider removing first itemizedOverlay from mapOverlays, not adding it again or calling plotPoints from onCreate instead of from onResume if suitable.

You can trace mapOverlays' size and test if this happens.

Please tell me if I am missunderstanding something.
kekomal
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Mar 17, 2010 10:44 am
Location: Bilbao, Spain

Postby R*BOMB » Mon May 10, 2010 9:28 pm

Huzzah! That helped a lot kekomal Thank you very much! Also i found that instead of drawing in draw() in itemized overlay, for those of you who run into a lag problem, it also helps a lot to make w/e you need drawn as a new overlay in itself.

Once again, Thank you very very very much kekomal.

R*BOMB
R*BOMB
Freshman
Freshman
 
Posts: 3
Joined: Thu May 06, 2010 11:44 pm

Top

Return to Map Problems

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests