Map of MapFragment gets loaded with lag when returning from another activity

梦想与她 提交于 2019-12-03 06:16:58

Reason: Its because as soon as you settings activity will be shown, the map activity will be on its onpause() state; thus, I assume android management reclaimed the memory from the map activity.

Solution: Make a static class and declare you map statically there, to avoid android from reclaiming the memory used by your map.

Ex.

//your static class
public class MapData{
  public static GoogleMap map;
}

//your map activity
public class MapActivity extends Activity{

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(MapData.map != null)
       MapData.map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!