0

I have an Android class that extends a FragmentActivity

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private double markerLat;
private double markerLon;
double[] toMark;
public final String LOG_TAG = MapsActivity.class.getSimpleName();
private DecimalFormat df1 = new DecimalFormat("#0.0");

SupportMapFragment mapFragment;
ActionBar actionBarFragment;
mapPositionListener mapMarker;

@Override
public void onAttachFragment(Fragment fragment) {
    super.onAttachFragment(fragment);

    Activity hostActivity = getParent();
    try {
        Log.d(LOG_TAG, "ERROR in try: " + fragment.getActivity().toString() + " ACTIVITY object " + hostActivity);
        mapMarker = (mapPositionListener) hostActivity;
    }
    catch (final ClassCastException e) {
        Log.d(LOG_TAG, "ERROR post catch: " + fragment.getActivity().toString() + " must implement mapPositionListener");
        throw new ClassCastException(fragment.getActivity().toString() + " must implement mapPositionListener");
    }
}

My current code return a Null object. How can I get the parent activity? My searches found lots of examples for the Fragment but none for the FragmentActivity class.

Volker Petersen
  • 283
  • 2
  • 8
  • 2
    Isn't getActivity() good enough for you to get the host activity? – Jörn Buitink Nov 16 '15 at 17:21
  • "Activity hostActivity = getActivity()" or "Activity hostActivity = (name of my host class)getActivity()" result in Android Studio error msg "Cannot resolve 'getActivity()' method. – Volker Petersen Nov 16 '15 at 19:08

0 Answers0