Bug 43815 - App.MainPage incorrect behaviour for view appearing and disappearing.
Summary: App.MainPage incorrect behaviour for view appearing and disappearing.
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2016-08-29 02:55 UTC by Jordan Foo
Modified: 2016-12-02 16:16 UTC (History)
6 users (show)

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

Example project with the bug. (5.36 MB, application/x-7z-compressed)
2016-08-29 02:55 UTC, Jordan Foo
Updated to XF2.3.107, Cleaned project (174.49 KB, application/x-7z-compressed)
2016-08-29 03:24 UTC, Jordan Foo

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 Jordan Foo 2016-08-29 02:55:21 UTC
Created attachment 17229 [details]
Example project with the bug.

The attached application showcase the problem that I am facing. I consider the behaviour as incorrect for Android, for iOS is behaving as expected.
The issue I am facing is switching MainPage property with navigation pages in the stacks, for android it is calling OnAppearing from the bottom up for every page that is in the stack as it is assigned I assign that NavigatePage to App.MainPage property. And then backing out of the pages, it no longer calls OnAppearing as it is considered "appeared" even though it is hidden behind.

From the sample: You can see the described behaviour by performing the following.
1. Start the app
2. Click GOTO PAGE 2 button
06-07 14:03:21.187 I/mono-stdout( 1994): NavigationPlay.PageTwo Appearing...
06-07 14:03:21.499 I/mono-stdout( 1994): NavigationPlay.MainPage Disappearing...
3. Click GOTO PAGE 3 button
06-07 14:03:28.599 I/mono-stdout( 1994): NavigationPlay.PageThree Appearing...
06-07 14:03:28.912 I/mono-stdout( 1994): NavigationPlay.PageTwo Disappearing...
06-07 14:03:37.646 I/mono-stdout( 1994): NavigationPlay.PageThree Disappearing...
06-07 14:03:37.653 I/mono-stdout( 1994): NavigationPlay.AlternateWorldPage Appearing...
Up to this point, all the log out put should show the lines for appearing and disappearing correctly.
5. Click Revert Button. We should be back to Page Three. This is were I have the problem.
The logs shows:
06-07 14:03:58.825 I/mono-stdout( 1994): NavigationPlay.AlternateWorldPage Disappearing...
06-07 14:03:58.832 I/mono-stdout( 1994): NavigationPlay.MainPage Appearing...
06-07 14:03:58.833 I/mono-stdout( 1994): NavigationPlay.PageTwo Appearing...
06-07 14:03:58.834 I/mono-stdout( 1994): NavigationPlay.PageThree Appearing...
6. Click back. Page two is not activated. As it is already a``ctivated.
06-07 14:05:24.504 I/mono-stdout( 1994): NavigationPlay.PageThree Disappearing...
7. Click back. Main Page is not activated. As it is already activated.
06-07 14:05:25.705 I/mono-stdout( 1994): NavigationPlay.PageTwo Disappearing...
8. Click back. Application leaves.

Note that this behavior is similar to what's reported in https://bugzilla.xamarin.com/show_bug.cgi?id=41322
However the key difference is that it already existed in XF2.0. And the fact that I am trying to change MainPage.
This also occurs for both FormsAppCompatActivity & FormsApplicationActivity
Comment 1 Jordan Foo 2016-08-29 03:24:51 UTC
Created attachment 17232 [details]
Updated to XF2.3.107, Cleaned project

I've updated the project submitted because that project was used in XF2.0. When I was asking for help in the forums. http://forums.xamarin.com/discussion/68295/app-mainpage-incorrect-behaviour-for-view-appearing-and-disappearing#latest

Do note that depending on whether you're using Compat Activity or not, the OnAppearing/OnDisappearing behaves differently, with FormsAppCompatActivity behaving worse.

FormsApplicationActivity switching back from alternate world.
[0:] NavigationPlay.AlternateWorldPage Disappearing...
[0:] NavigationPlay.PageThree Appearing...
[0:] NavigationPlay.MainPage Appearing...
[0:] NavigationPlay.PageTwo Appearing...

FormsAppCompatActivity switching back from alternate world.
[0:] NavigationPlay.AlternateWorldPage Disappearing...
[0:] NavigationPlay.PageThree Appearing...
[0:] NavigationPlay.MainPage Appearing...
[0:] NavigationPlay.MainPage Disappearing...
[0:] NavigationPlay.PageTwo Appearing...
[0:] NavigationPlay.PageTwo Disappearing...
[0:] NavigationPlay.MainPage Appearing...
[0:] NavigationPlay.PageTwo Appearing...
Comment 2 adrianknight89 2016-09-10 21:53:23 UTC
I submitted a PR in case it fixes your use case. Please see https://github.com/xamarin/Xamarin.Forms/pull/342
Comment 3 Samantha Houts [MSFT] 2016-09-30 23:15:02 UTC
The PR referenced in Comment 2 will be included in 2.3.4-pre1 (not yet released). If you are still experiencing this issue after updating your packages at the time of release, please reopen this report. Thank you!
Comment 4 Parmendra Kumar 2016-12-02 16:16:23 UTC
I have checked this issue with 2.3.4-pre1 and observed that this issue has been fixed.

Hence closing this issue.