Bug 52490 - OnAppearing/OnDisappearing Behaves differently between iOS and Android
Summary: OnAppearing/OnDisappearing Behaves differently between iOS and Android
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.3
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
Depends on:
Reported: 2017-02-14 04:18 UTC by ray.qu
Modified: 2017-02-22 16:35 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description ray.qu 2017-02-14 04:18:37 UTC
OnAppearing gets invoked when App comes to foreground in Android in a view hierarchy of either:
1. NavigationPage's child -> TabbedPage's child-> Page1, Page1's OnAppearing will be invoked when Android comes to the foreground.
1. TabbedPage child -> NavigationPage child -> Page1, Page1's OnAppearing will be invoked when Android comes to the foreground.

Same applies to OnDisappearing when Android App goes to background.

#Expected Behavior:
The OnAppearing and OnDisappearing should not be invoked when App goes to background or foreground.

Test Project is attached.
Comment 1 adrianknight89 2017-02-17 23:46:59 UTC
iOS and Android have been inconsistent for a long time. I do not think this will change. For example, we can't start triggering appearing / disappearing events for iOS all of a sudden and break compatibility.

If you want consistency, you can disable these events for Android and use pub/sub in app sleep / resume for cross platform approach.

You can use SendAppearingEventOnResume / SendDisappearingEventOnPause platform-specific options to turn on and off these events on Android.
Comment 2 ray.qu 2017-02-21 00:35:39 UTC
If you publish app sleep / resume event, which method in Page1 would you subscribe? If Page1 subscribes "AppResume" in OnAppearing and unsubscribe it in OnDisappearing, then you will never receive the event as OnAppearing invoked after App sends out "AppResume". However, if you subscribe "AppResume" in Page1's constructer method, then it will cause memory problem as "AppResume" event can never be unsubscribed. So even Page1 gets popped out, it will still receive the event
Comment 3 Paul DiPietro [MSFT] 2017-02-22 16:35:40 UTC
I would redirect you to this thread on the Forms evolution forum for discussion about potential lifecycle changes: https://forums.xamarin.com/discussion/84510/improved-life-cycle-support#latest