Resolve crash when navigating to PopupPage after app is sent to background #150
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for a crash that occurs on Android when navigating to a PopupPage under specific conditions, such as when the application is sent to the background while a task is still running.
Steps to Reproduce:
NavigationPage
toApp.Current.MainPage
, navigating to a page that, in itsOnAppearing
method, triggers a navigation to aPopupPage
.Example:
Cause of the Crash:
AddAsync
method of theAndroidMopups
class whenpage.Parent.Handler
isnull
. Specifically, this happens while attempting to create a newPopupPageHandler
instance usingpage.Parent.Handler.MauiContext
, which results in a null reference exception.Solution:
FindMauiContext
extension method to traverse the visual tree and retrieve a validMauiContext
ifpage.Parent.Handler.MauiContext
isnull
.AddAsync
method to use this method to ensure a valid context is available before creating thePopupPageHandler
.Related Issue:
This fix also resolves a similar issue described in Issue #118
The changes in this PR address the root cause of this issue by ensuring a valid MauiContext is available during navigation.