{"record":{"id":"bcccacb61e0dc740","repo":"dotnet/maui","slug":"removepage-is-not-supported-globally-on-android-p","errorCode":null,"errorMessage":"RemovePage is not supported globally on Android, please use a NavigationPage.","messagePattern":"RemovePage is not supported globally on Android, please use a NavigationPage\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/Android/AppCompat/Platform.cs","lineNumber":220,"sourceCode":"\t\t\tCurrentPageController?.SendDisappearing();\n\t\t\tUpdateAccessibilityImportance(CurrentPageController as Page, ImportantForAccessibility.NoHideDescendants, false);\n\n\t\t\t_navModel.PushModal(modal);\n\n\t\t\tTask presentModal = PresentModal(modal, animated);\n\n\t\t\tawait presentModal;\n\n\t\t\tUpdateAccessibilityImportance(modal, ImportantForAccessibility.Auto, true);\n\n\t\t\t// Verify that the modal is still on the stack\n\t\t\tif (_navModel.CurrentPage == modal)\n\t\t\t\t((IPageController)modal).SendAppearing();\n\t\t}\n\n\t\tvoid INavigation.RemovePage(Page page)\n\t\t{\n\t\t\tthrow new InvalidOperationException(\"RemovePage is not supported globally on Android, please use a NavigationPage.\");\n\t\t}\n\n\t\tpublic static SizeRequest GetNativeSize(\n\t\t\tIVisualElementRenderer visualElementRenderer,\n\t\t\tdouble widthConstraint,\n\t\t\tdouble heightConstraint)\n\t\t{\n\t\t\tvar context = visualElementRenderer.View.Context;\n\n\t\t\t// negative numbers have special meanings to android they don't to us\n\t\t\twidthConstraint = widthConstraint <= -1 ? double.PositiveInfinity : context.ToPixels(widthConstraint);\n\t\t\theightConstraint = heightConstraint <= -1 ? double.PositiveInfinity : context.ToPixels(heightConstraint);\n\n\t\t\tbool widthConstrained = !double.IsPositiveInfinity(widthConstraint);\n\t\t\tbool heightConstrained = !double.IsPositiveInfinity(heightConstraint);\n\n\t\t\tint widthMeasureSpec = widthConstrained\n\t\t\t\t\t\t\t? MeasureSpecFactory.MakeMeasureSpec((int)widthConstraint, MeasureSpecMode.AtMost)","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/Android/AppCompat/Platform.cs#L202-L238","documentation":"Thrown by the Platform class's explicit INavigation.RemovePage implementation. Removing a page from the back stack is a NavigationPage operation on Android; the global platform only supports modal navigation and therefore rejects RemovePage.","triggerScenarios":"Calling Application.Current.MainPage.Navigation.RemovePage(page) on Android when MainPage is not a NavigationPage. Often hit when trying to clean up the navigation stack after a login flow.","commonSituations":"Post-login flow that removes the login page from the stack without a NavigationPage host. Shared code calling RemovePage that works on iOS but fails on Android.","solutions":["Use a NavigationPage as the root so RemovePage is handled by the NavigationPage renderer.","For modal-based flows, pop the modal instead of removing it from a stack.","Restructure the navigation graph so the page you want to remove is part of a NavigationPage's stack."],"exampleFix":"// before\nApplication.Current.MainPage = new LoginPage();\n// after login\nApplication.Current.MainPage.Navigation.RemovePage(loginPage); // throws\n\n// after\nApplication.Current.MainPage = new NavigationPage(new LoginPage());\nApplication.Current.MainPage.Navigation.RemovePage(loginPage);","handlingStrategy":"validation","validationCode":"// Only RemovePage when inside a NavigationPage.\nvar np = NavigationPage.GetNavigationPage(currentPage);\nif (np != null)\n    np.Navigation.RemovePage(pageToRemove);\nelse\n    await currentPage.Navigation.PopModalAsync();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a NavigationPage root for any flow that removes pages from the stack (e.g., post-login cleanup).","For modal-only flows, pop the modal instead of removing it.","Centralize navigation in a service that validates the host before calling RemovePage."],"tags":["android","navigation","removepage","navigationpage","platform"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}