android swipe Horizontal View Paging with MapView

坚强是说给别人听的谎言 提交于 2019-12-06 01:44:31

I am guessing that your crashing is an IllegalStateException caused by instantiating multiple mapviews?

You are correct that the mapview is launching from the second view, the viewpager prepares the views on either side so that it can transition smoothly when the user wants to change tabs. It does this by actually loading them. (Use the hierarchyviewer tool in your android sdk to check this out sometime).

Anyways, try using this onDestroy method:

@Override
public void onDestroy() {
    super.onDestroy();

    ((ViewGroup) map.getParent()).removeView(map);
}

It should remove the mapview whenever the view is destroyed, making it ready for re-use.

If that fails, try also making your mapview static:

private static MapView mapview;

then, if multiple instances of your map tab are somehow created, they can use the same mapview.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!