Can I use fragment.getContext at lower than API 23?

Viewed 883

I'm making now googleMap Fragment.

 @Override
    public void onMapReady(GoogleMap googleMap) {
        MapsInitializer.initialize(getContext());

        mGoogleMap = googleMap;
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

        googleMap.addMarker();

        ...
    }

But in this code, getContext is available for API 23 or more. Is there a method instead getContext??

3 Answers

public static synchronized int initialize (Context context)

Initializes the Google Maps Android API so that its classes are ready for use. If you are using MapFragment or MapView and have already obtained a (non-null) GoogleMap by calling getMapAsync() on either of these classes, then it is not necessary to call this.

if(FRAGMENT) Then

You should use getActivity()

MapsInitializer.initialize(getActivity());

Use getActivity() instead of getContext();

MapsInitializer.initialize(getActivity());

You can also use Application instance's getApplicationContext() method

Related