2

I load a WebView into a fragment as a child fragment. Using a button, I then transition to a Google Map using the TransitionManager. The map loads. Then I tap on another button to transition back to the WebView. The WebView displays. But when I tap on the button to transition back to the Map, I get an "Error inflating class fragment".

For some reason, the TransitionManager cannot inflate the scene again. I reuse the same scene containing the Google Map. I even tried reinitializing the Scene with:

Scene.getSceneForLayout(sceneRoot, R.layout.activity_maps, context);

but it didn't help. Does Google Maps have a problem being reinitialized after it gets destroyed when being shown from a fragment?

UPDATE: I think I may have found the solution (need to try it out with transitions): android maps v2 crashes when reopened in fragment

Community
  • 1
  • 1
Johann
  • 27,536
  • 39
  • 165
  • 279

1 Answers1

0

In my case, I just needed use this code with fragments, when I was using navigation drawer. I hope it works!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainl"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

</RelativeLayout>

MainActivity

public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction();
        SupportMapFragment mFRaFragment = new MapFragmentD();
        Bundle args = new Bundle();
        args.putDouble("lat", 30.375321);
        args.putDouble("lng", 69.345115);
        mFRaFragment.setArguments(args);
        mTransaction.add(R.id.mainl, mFRaFragment);
        mTransaction.commit();

        try {
            MapsInitializer.initialize(getApplicationContext());
        } catch (GooglePlayServicesNotAvailableException e) {
            e.printStackTrace();
        }
    }



}

MapFragmentD

public class MapFragmentD extends SupportMapFragment {

    GoogleMap mapView;
    private static LatLng position ;
//  ArrayList<Map> mapclass;
    @Override
    public void onCreate(Bundle arg0) {
        super.onCreate(arg0);
    }

    @Override
    public View onCreateView(LayoutInflater mInflater, ViewGroup arg1,
            Bundle arg2) {
        return super.onCreateView(mInflater, arg1, arg2);
    }

    @Override
    public void onInflate(Activity arg0, AttributeSet arg1, Bundle arg2) {
        super.onInflate(arg0, arg1, arg2);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);


//      mapclass = (ArrayList<Map>)getArguments().getSerializable("Map");

        mapView = getMap();
        mapView.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//      for(int i = 0; i < mapclass.size(); i++)
//      {
            position = new LatLng(getArguments().getDouble("lat"), getArguments().getDouble("lng"));
            MarkerOptions markerOptions = new MarkerOptions();
            markerOptions.draggable(true);
            markerOptions.position(position);
            markerOptions.title("test");
//          markerOptions.snippet(mapclass.get(i).getSpeciality());

            markerOptions.icon(BitmapDescriptorFactory.defaultMarker());
            mapView.addMarker(markerOptions);
//      }

        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(position) 
        .zoom(7)                  
        .bearing(90) 
        .tilt(30)    
        .build();    
        mapView.animateCamera(CameraUpdateFactory.newCameraPosition(
                cameraPosition));



    }
}
Mardoqueu
  • 1
  • 7