8

My app has three different Activities that use a SupportMapFragment. There is a major delay on the first load after starting the app. This slow load time does not occur on subsequent loads, even if I go back and access a completely different Activity (that also contains a map). I'm trying to figure out if this is something that I could fix.

This gist shows how I load the SupportMapFragment. Using debug points I have determined that the slowness occurs between onViewCreated and onStart.

Update 1: Using Debug I have taken two traces of the first load and second load. The second load is in a completely different Activity. I quickly noticed that the first trace (the slow load) has a LOT of calls to java/util/zip/zipEntry. I don't see any calls like that in the second trace. Also, this delay happens between onCreateView and onViewCreated of the MapFragment.

Update 2: This also happens with a MapFragment (not support), except the delay is actually much longer.

Update 3: This SO question seems to be related. Also this one.

Community
  • 1
  • 1
theblang
  • 10,215
  • 9
  • 69
  • 120
  • Why are you using nested fragments, rather than extending `SupportMapFragment` or just using it directly? – CommonsWare Nov 17 '14 at 16:23
  • 1
    @CommonsWare I am using it in a `ViewPager`, so I load a `Fragment` that loads and configures the `SupportMapFragment`. – theblang Nov 17 '14 at 16:25
  • "I am using it in a ViewPager" -- so? That does not justify the overhead and general icky-ness of nested fragments. [Here is a sample project](https://github.com/commonsguy/cw-omnibus/tree/master/MapsV2/Pager) showing using maps in a `ViewPager`, without nested fragments. Note that I happen to be using `MapFragment` rather than `SupportMapFragment`, but that should not impact the solution. If you want to use nested fragments in places, go right ahead, but do so only in the absence of less-expensive solutions. – CommonsWare Nov 17 '14 at 16:28
  • @CommonsWare I have refactored such that the `ViewPager` is in the Activity and the `CustomMapFragment` is a direct Fragment. There is still almost a two second delay when first loading. Could this be an issue with the `SupportMapFragment`? I could convert since we dropped API 10 support after our last version release. – theblang Nov 17 '14 at 17:05
  • "Could this be an issue with the SupportMapFragment?" -- tough to say, but I doubt it. Use Traceview to determine where your time is being spent, rather than just log statements. My guess is much of this time is part of initializing the communications with the Play Services Framework and it starting to download map tiles, and that's not something that you can readily change. – CommonsWare Nov 17 '14 at 17:07
  • Using `Debug` I have taken two traces of the first load and second load. The second load is in a completely different `Activity`. I quickly noticed that the first trace (the slow load) has a LOT of calls to `java/util/zip/zipEntry`. I don't see any in the second trace. Also, this delay happens between `onCreateView` and `onViewCreated`. – theblang Nov 17 '14 at 19:51
  • @CommonsWare It is seeming like there is no way around the delay, which I hate because it effects neighboring fragments in the ViewPager too (OffscreenPageLimit has to be at least 1). – theblang Nov 17 '14 at 21:19
  • See my answer over there http://stackoverflow.com/a/29246677/3757624. It is still working. – Xyaren May 09 '15 at 12:09
  • Possible duplicate of [what makes my map fragment loading slow?](http://stackoverflow.com/questions/26265526/what-makes-my-map-fragment-loading-slow) – marmor Nov 04 '15 at 07:51

0 Answers0