10

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:

  1. 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.
  2. 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.

See this video: http://www.youtube.com/watch?v=12SEotktlXI

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

Testing environment: Nexus 5, Android 4.4.2, unrooted

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

ercan
  • 1,639
  • 1
  • 20
  • 34
  • Have tried to test it on other devices? I noticed it only on Nexus 5.. Galaxy S3 showed different behavior... – Emil Adz Feb 16 '14 at 21:03
  • Yes, definitely. I tried it on HTC Desire SV, and there was no lag. I think that's because they don't use transition animations. When I turn transition animations off on my Nexus 5 (settings > developer options > transition animations), the lag disappears too. – ercan Feb 16 '14 at 21:22
  • So it's something related to KitKat... maybe a bug. – Emil Adz Feb 17 '14 at 00:01
  • I think it's a maps API bug because all other views get loaded immediately but only the map doesn't... – ercan Feb 17 '14 at 13:17

1 Answers1

-3

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();
  }
}
Rick Royd Aban
  • 904
  • 6
  • 33
  • At least make sure that onDestroy the static var is cleaned up. – neteinstein Feb 26 '14 at 14:53
  • Sorry but that didn't work. I replaced every occurence of `mMap` in RetainMapDemoActivity example with `MapData.map` but the map still has lag when I come back from the dummy activity... :( – ercan Feb 26 '14 at 15:59