Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Reference Exception when pushing a Mopup in OnAppearing() on Android #110

Open
melvyniandrag opened this issue Feb 23, 2024 · 1 comment

Comments

@melvyniandrag
Copy link

Title + code below explain the issue.

Porting a Xamarin app to MAUI. We had an RG popup that would get shown inside OnAppearing() of the main page of the app. After porting to MAUI, this gives a null ref exception, unless I put the mopup PushAsync() inside Device.BeginInvokeOnMainThread.

Here is a demo application on github that illustrates the bug. That link has the relevant code excerpt + a pic of the error message in the readme.

VS 2022 v17.9.0
Mopups 1.3.0

@melvyniandrag
Copy link
Author

melvyniandrag commented Feb 29, 2024

Update another way around this is to add a delay before the PushAsync. 1 second was sufficient on iOS, but on windows I've had to add a 3 second delay.

        private const int DELAY_FOR_MOPUPS_TO_NOT_CRASH_WITH_NULL_REF_EXCEPTION = 3000;

        protected override async void OnAppearing()
        {
            base.OnAppearing();
            Debug.WriteLine("MainPage - OnAppearing()");
            Microsoft.Maui.Devices.DeviceDisplay.KeepScreenOn = true;
            showOnAppearingPopups();

        }

        private async void showOnAppearingPopups()
        {
            await Task.Delay(DELAY_FOR_MOPUPS_TO_NOT_CRASH_WITH_NULL_REF_EXCEPTION);
            await MopupService.Instance.PushAsync(new MyCustomPopupPage());
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant