In a default SupportMapFragment
the MapView is being loaded and created when the Fragment is instantied thus doing the heavy work on the Main Thread.
The log below happens before getMapAsync(this);
is called and it is the moment when the Main Thread freezes for about 2 seconds. The log proves somehow that everything is being created before getMapAsync()
.
Isn't the map supposed to load ONLY when getMapAsync()
is called?
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Enabling debug mode 0
D/OpenGLRenderer: endAllActiveAnimators on 0xb7966f90 (RippleDrawable) with handle 0xb7988688
I/AppCompatViewInflater: app:theme is now deprecated. Please move to using android:theme instead.
I/zzy: Making Creator dynamically
W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
W/art: Suspending all threads took: 5.704ms
D/ChimeraCfgMgr: Loading module com.google.android.gms.maps from APK /data/data/com.google.android.gms/app_chimera/chimera-module-root/module-fcfb08c37b9ca44c48d9936b0e1895ef8b9cffe0/MapsModule.apk
D/ChimeraModuleLdr: Loading module APK /data/data/com.google.android.gms/app_chimera/chimera-module-root/module-fcfb08c37b9ca44c48d9936b0e1895ef8b9cffe0/MapsModule.apk
D/ChimeraFileApk: Primary ABI of requesting process is armeabi-v7a
D/ChimeraFileApk: Classloading successful. Optimized code found.
I/Google Maps Android API: Google Play services client version: 7895000
I/Google Maps Android API: Google Play services package version: 8115236
I/e: Token loaded from file. Expires in: 393978062 ms.
I/e: Scheduling next attempt in 393678 seconds.
I/Choreographer: Skipped 44 frames! The application may be doing too much work on its main thread.
This is the fragment:
public class StoreMapFragment extends SupportMapFragment
implements OnMapReadyCallback {
private GoogleMap mMap;
public static StoreMapFragment newInstance() {
StoreMapFragment fragment = new StoreMapFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
loadStores();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setRetainInstance(true);
}
public void loadStores() {
if(mMap == null)
return;
// Add markers
}
}
Related: