地图MapFragment从另一个活动返回时被装载滞后地图、MapFragment

2023-09-06 04:23:44 作者:觅友

据我所看到的, MapFragment 有一个问题,过渡动画。在布局上的所有意见都得到立即显示,包括MapFragment自己的看法(如缩放按钮)。但是,地图本身被加载的动画完成后,才滞后。

As far as I can see, MapFragment has an issue with transition animations. All views on the layout are getting shown immediately, including the MapFragment's own views (like zoom buttons). But the map itself gets loaded with a lag only after the animation is completed.

为了说明问题,我做了以下内容:

In order to illustrate the problem, I did the following:

我在谷歌地图Android的API的例子改变的活动之一咯。它打开通过实施项目的空白活动。当我点击后退按钮,地图上被载入,但过渡完成后才能使用。 我夸大了过渡效果一点点,这样就可以看到这个问题比较好。我将过渡动画速度在开发选项为 5倍。即使是在1X速度,这种滞后是令人不安的,但。 I changed one of the Activities in the Google maps android API examples slightly. It opens a blank activity via an Action Item. When I click back button, the map gets loaded, but only after the transition is completed. I exaggerated the transition effect a little bit, so that you can see the problem better. I set the transition animation speed in Developer Options to 5x. Even on 1x speed, this lag is disturbing though.

请参阅此视频: http://www.youtube.com/watch?v=12SEotktlXI

你有什么建议,以prevent这种滞后?为什么所有的观点立即得到加载,而是地图本身不?

Do you have any suggestion to prevent this lag? Why do all views get loaded immediately but the map itself doesn't?

测试环境:5的Nexus的Andr​​oid 4.4.2,无根

Testing environment: Nexus 5, Android 4.4.2, unrooted

编辑:这个问题也occures当MapView类是用来代替MapFragment

This problem also occures when MapView is used instead of MapFragment.

推荐答案

原因:它的,因为一旦你的设置将显示活动,该活动地图将成为其在onPause()状态;因此,我认为Android的回收管理从地图活动的内存。

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.

例。

//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();
  }
}