{"record":{"id":"b0ac4cdd6e1930eb","repo":"microg/GmsCore","slug":"oncreateview-not-allowed-on-mapviewdelegate","errorCode":null,"errorMessage":"onCreateView not allowed on MapViewDelegate","messagePattern":"onCreateView not allowed on MapViewDelegate","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"play-services-maps/src/main/java/org/microg/gms/maps/MapViewDelegate.java","lineNumber":36,"sourceCode":"import com.google.android.gms.maps.OnMapReadyCallback;\nimport com.google.android.gms.maps.internal.IGoogleMapDelegate;\nimport com.google.android.gms.maps.internal.IMapViewDelegate;\nimport com.google.android.gms.maps.internal.IOnMapReadyCallback;\nimport com.google.android.gms.maps.model.RuntimeRemoteException;\n\npublic class MapViewDelegate implements MapLifecycleDelegate {\n    private final ViewGroup container;\n    private final IMapViewDelegate delegate;\n    private View view;\n\n    public MapViewDelegate(ViewGroup container, IMapViewDelegate delegate) {\n        this.container = container;\n        this.delegate = delegate;\n    }\n\n    @Override\n    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) {\n        throw new UnsupportedOperationException(\"onCreateView not allowed on MapViewDelegate\");\n    }\n\n    @Override\n    public void onCreate(@Nullable Bundle savedInstanceState) {\n        try {\n            Bundle temp = new Bundle();\n            MapsBundleHelper.transfer(savedInstanceState, temp);\n            delegate.onCreate(temp);\n            MapsBundleHelper.transfer(temp, savedInstanceState);\n            view = (View) ObjectWrapper.unwrap(delegate.getView());\n            container.removeAllViews();\n            container.addView(view);\n        } catch (RemoteException e) {\n            throw new RuntimeRemoteException(e);\n        }\n    }\n\n    @Override","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-maps/src/main/java/org/microg/gms/maps/MapViewDelegate.java#L18-L54","documentation":"MapViewDelegate extends the lifecycle delegate of MapView but deliberately does not support onCreateView: the MapView manages its own view hierarchy through the container passed to the delegate, so an external inflater-based view creation is a programming error. Calling it throws UnsupportedOperationException unconditionally. This mirrors the restriction that view creation must go through MapView itself, not the delegate.","triggerScenarios":"Calling mapViewDelegate.onCreateView(inflater, parent, savedInstanceState) directly, or using MapViewDelegate in a custom fragment/adapter where a Fragment's onCreateView implementation forwards to the delegate instead of using MapView.","commonSituations":"Migrating code written against the Google Maps SDK's internal delegate APIs to microG, embedding the map in a Fragment with copy-pasted lifecycle plumbing, or reflection-based frameworks calling all LifecycleDelegate methods.","solutions":["Do not call onCreateView on MapViewDelegate; use MapView (or MapFragment) to create the map view.","In a Fragment, inflate/place a MapView yourself and forward only onCreate/onStart/onResume/onPause/onStop/onDestroy/onSaveInstanceState/onLowMemory to it.","If you hold a delegate from MapView, only invoke the lifecycle methods MapView documents as supported.","Check for a library version change: code that relied on this method working will never work; restructure the call site."],"exampleFix":"// before\n@Override\npublic View onCreateView(LayoutInflater inf, ViewGroup p, Bundle s) {\n    return delegate.onCreateView(inf, p, s); // always throws\n}\n// after\n@Override\npublic View onCreateView(LayoutInflater inf, ViewGroup p, Bundle s) {\n    mapView.onCreate(s);\n    return mapView; // MapView already inflated via MapView(inflater, attrs)\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"public static boolean supportsViewCreation(LifecycleDelegate d) {\n    return !(d instanceof MapViewDelegate);\n}","tryCatchPattern":"try {\n    view = delegate.onCreateView(inflater, parent, savedInstanceState);\n} catch (UnsupportedOperationException e) {\n    view = mapView; // fall back to the owning MapView\n}","preventionTips":["Never create views through MapViewDelegate; view creation belongs to MapView/MapFragment.","In Fragments, construct MapView yourself in onCreateView and forward only supported lifecycle methods.","Do not reflectively invoke every LifecycleDelegate method; consult the supported set.","Search your codebase for '.onCreateView(' calls on delegates during migration reviews."],"tags":["android","maps","unsupported-operation","lifecycle"],"backgroundTag":"unsupported-operation","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}