在我的应用程序中有一个 MapView,我向其中添加了 OverlayItems,大约 500,但将来它会更多甚至数千......
我的问题是:当我切换到这个活动时,我遇到了 3-4 秒的大停电,然后它会正确切换,我可以导航并点击地图。
几个月前,当应用程序在 mapView 中仅包含 50-150 个 GeoPoints 时,并没有停电。所以我认为我的 OverlayItem 添加到 mapView 有问题,它确实会减慢应用程序的速度。
我在 Activity 启动时通过一个简单的循环添加我的 GeoPoints。
我能做些什么来加快这个活动并防止停电?
编辑:
多亏了评论,我才意识到我在每次addOverlay(MyOverlayItem myoverlay)函数调用之后调用 populate() 。
我编辑了代码,现在在循环之后我只调用它一次:
public void populateNow()
{
populate();
}
但我刚刚得到了一个很好的空指针异常......有什么想法吗?
11-12 15:54:03.398: E/MapActivity(1534): Couldn't get connection factory client
11-12 15:54:03.531: E/AndroidRuntime(1534): FATAL EXCEPTION: main
11-12 15:54:03.531: E/AndroidRuntime(1534): java.lang.NullPointerException
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.google.android.maps.ItemizedOverlay.getIndexToDraw(ItemizedOverlay.java:211)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.google.android.maps.ItemizedOverlay.draw(ItemizedOverlay.java:240)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.google.android.maps.Overlay.draw(Overlay.java:179)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.google.android.maps.OverlayBundle.draw(OverlayBundle.java:42)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.google.android.maps.MapView.onDraw(MapView.java:530)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.View.draw(View.java:6933)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.View.draw(View.java:6936)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.View.draw(View.java:6936)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.widget.FrameLayout.draw(FrameLayout.java:357)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewRoot.draw(ViewRoot.java:1527)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.os.Looper.loop(Looper.java:123)
11-12 15:54:03.531: E/AndroidRuntime(1534): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-12 15:54:03.531: E/AndroidRuntime(1534): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 15:54:03.531: E/AndroidRuntime(1534): at java.lang.reflect.Method.invoke(Method.java:507)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
11-12 15:54:03.531: E/AndroidRuntime(1534): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
11-12 15:54:03.531: E/AndroidRuntime(1534): at dalvik.system.NativeStart.main(Native Method)