Xamarin.forms: [Bug] Disappearing event behavior during backgrounding not consistent between the platforms.

Created on 29 Sep 2019  路  8Comments  路  Source: xamarin/Xamarin.Forms

Description

I tried three methods to handle page Disapearing.

In the code

this.Disappearing += MainPage_Disappearing;

Overriding

protected override void OnDisappearing()
{
   Debug.WriteLine("OnDisappearing()");

   base.OnDisappearing();
}

And the event handler from XAML

private void ContentPage_Disappearing(object sender, EventArgs e)
{
    Debug.WriteLine("ContentPage_Disappearing()");
}

Neither of the three handler is called on UWP and WPF. They were called all three on Android.

Steps to Reproduce

Basicaly generate a new XF solution and implement the Disappearing handlers.

The test solution is attached.

XFBug_UWP_OnDisappearing.zip

lifecycleevents help wanted Android bug up-for-grabs

All 8 comments

@ZeProgFactory can you expand on what you are doing that should trigger Disappearing?

Are you saying if you background or minimize it's not called?

Then event should trigger for example when the page closes:
https://docs.microsoft.com/en-us/dotnet/api/Xamarin.Forms.Page.Disappearing?view=xamarin-forms
And in past past the event shows up when the page was backgrounded.

@ZeProgFactory can you expand on what you are doing to the UWP app that maps to a page close

Then event should trigger for example when the page closes:

I agree that it doesn't fire when you minimize the UWP or background the UWP. Are those the two scenarios you are talking about?

From my tests disappearing/appearing all fire fine if you navigate away from a page

I just updated the test solution from 鈥榅amarin.Forms 4.2.0.815419' to 'Xamarin.Forms.4.2.0.848062'.
The three Debug.WriteLine() were still hit when exiting the program on Android (physical back button) but never on UWP/Windows (close app by clicking on the cross on the windows frame).

XFBug_UWP_OnDisappearing (2).zip

I just updated the test solution from 鈥榅amarin.Forms 4.2.0.815419' to 'Xamarin.Forms.4.2.0.848062'.
The three Debug.WriteLine() were still hit when exiting the program on Android (physical back button) but never on UWP/Windows (close app by clicking on the cross on the windows frame).

I think that's still two different life cycle events that you're expressing here. When you hit the physical back button on android that's just backgrounding the app. The app process is still in memory but the view get detached from the window (disappearing event fires)

If you click the X on the windows frame that's physically terminating the app. The equivalent to that on Android would be swipe closing the app which also does not fire the disappearing event

I think the question is not if it鈥檚 or not two different cycle events, but whether the reaction is consistent over the platforms and in time. On the two platforms (didn鈥檛 test on the other ones) I start the App and exited it from the user point of view. On one platform I get the all events fired not on the other.

So, it鈥檚 not consistent for Android and UWP.

If you the considered page is at least the second in the NavigationStack the events were fired on UWP when popping the page, but not when ending the program. Obviously, the page disappears in the two cases!

On Android the events fire in the two cases!!!

So we can argue to the end of times, unfortunately it won鈥檛 change the facts.

iOS behaves the same as UWP - backgrounding does not fire the Disappearing event. So Android is the odd one out on this.

So we need to bring Android in line with the other platforms - it should happen when popping a page off the stack, but not when the entire app is backgrounded.

(I suspect we _might_ have the Android disappearing event tied to a Dispose() call, which would explain why it's happening during backgrounding, and also be wrong for other reasons.)

If in your understanding, when an App is backgrounding, the contained pages are "not disappearing", we probably need a "backgrounding event". That's also fine for me. It doesn't matter how you call it but when page passes from being displayed to not being displayed (close, hide, ... ) there should be an event.

Was this page helpful?
0 / 5 - 0 ratings