我有一个扩展FragmentActivity的Android类
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");
}
}
我当前的代码返回一个Null对象。我怎样才能获得父活动? 我的搜索发现了许多Fragment的例子,但没有FragmentActivity类的例子。