Siddharth Garg Siddharth Garg - 3 years ago 171
Android Question

Android: onMapLoaded not called when map is hidden initially

I have a

in my Activity. I have set the visibility of this layout to hidden initially.

In my Map fragment, I have overridden the
method and am loading some markers and zooming using bounds. My activity has some buttons which when pressed make the map visible and center on the location without messing the initial zoom.

Problem is,
does not get called until the map has become visible (i.e. it gets called only after the layout's visibility has been changed by a button click.). So if I start my app and click the button, map centers on the marker with default zoom.

How can I ensure
gets called even though the map is hidden?

NOTE I am not looking for hacking my code to make this happen. If i want hacks, I can just make the map visible and overlay it with some full screen view to hide it. I am looking for a proper solution to How to ensure onMapLoaded gets called even though the map fragment is hidden (if such a solution exists)

Answer Source

As described in Official Documentation:

public abstract void onMapLoaded ()

Called when the map has finished rendering. This will only be called once. You must request another callback if you want to be notified again.

This is called on the Android UI thread.

So seems it can't be called while map fragment is hidden. Moreover it newer be called even map is visible but it "is continuously changing and never completes loading due to the user constantly interacting with the map.".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download