EDIT: getMap
is deprecated now
The problem is when the call to getMap is null, when can I try again?
That depends upon the nature of the problem.
If you set up the SupportMapFragment
via the <fragment>
element in the layout, you can call getMap()
successfully in onCreate()
. But, if you create the SupportMapFragment
via the constructor, that’s too soon — the GoogleMap
does not yet exist. You can extend SupportMapFragment
and override onActivityCreated()
, as getMap()
is ready by then.
However, getMap()
can also return null
for a bigger problem, such as Google Play Services not being installed. You would need to use something like GooglePlayServicesUtil.isGooglePlayServicesAvailable()
to detect this condition and deal with it however you wish.