Bug 31453 - Navigation.RemovePage doesn't work inside OnDisappearing
Summary: Navigation.RemovePage doesn't work inside OnDisappearing
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.4
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-29 04:25 UTC by mehdy
Modified: 2016-11-02 15:10 UTC (History)
7 users (show)

Tags: ac
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:
Status:
VERIFIED FIXED

Description mehdy 2015-06-29 04:25:06 UTC
I create pages dynamically based on page class name like this:

async void listItem_tapped(object tappedItem)
		{
			var newPage=(Page) Activator.CreateInstance(Type.GetType(((fooClass)tappedItem)).PageName);
			await this.Navigation.PushAsync (newPage,false);
		}

and I remove pages from navigation stack on Disappearing ,

protected async override void OnDisappearing ()
		{
                        base.OnDisappearing();
			this.Content = null;
			Navigation.RemovePage(this);
		}

The issue is that the pages are left in Navigation stack and RemovePage has no effect on them.
I tested it in Xamarin.Forms v1.4.2.6359 on ios simulator of Xamarin Studio v5.9.4.
Comment 1 Parmendra Kumar 2015-07-01 13:41:08 UTC
@mehdy

I have checked this issue but unable to reproduce it.
Could you please provide us sample project so that I can reproduce this issue at my end.

Thanks.
Comment 2 mehdy 2015-07-17 01:56:35 UTC
the issue only happens on xamarin.forms on android.
calling Navigation.RemovePage in OnDisappering will trigger OnDisappering method again and this creates an infinite loop and will crash the application with stack over flow.
here is a sample project with two pages, page one has a button for navigating to page two and tries to remove page1 in OnDisappering

https://drive.google.com/file/d/0B9IVabQTVlSlYzhHYkx5TkhNU1U/view?usp=sharing
Comment 3 mehdy 2015-07-17 01:57:08 UTC
it works correctly without crash in xamarin.forms ios application
Comment 4 Parmendra Kumar 2015-07-21 14:17:44 UTC
I have checked this issue with provided sample in comment #2 and getting same behavior as mentioned in comment #2.

Screencast: http://www.screencast.com/t/JVEWdDbgEA

ApplicationOutput: https://gist.github.com/Parmendrak/507d0559ab1a1e17126e
XAPLog: https://gist.github.com/Parmendrak/69ade5a8bfa32d2694a7
IDELog: https://gist.github.com/Parmendrak/7fab610dd1c0edbbc401

Environment info:
Xamarin Studio 5.9.4 (build 5)
Mono 4.0.2 ((detached/c99aa0c)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.2 (6776)
Xamarin.Mac : 2.0.2.35 (Enterprise Edition)
Xamarin.iOS: 8.10.3.2 (Enterprise Edition)
Xamarin.Android : 5.1.5.2 (Enterprise Edition)
Mac OS X 10.9.4
Comment 5 Chris King 2015-07-31 14:28:56 UTC
Removing the page from the navigation stack in OnDissapearing event causes Android application to crash.
Comment 6 adrianknight89 2016-11-02 06:22:54 UTC
This issue is not happening for me on 2.3.3.-pre3. Can you re-test?
Comment 7 Parmendra Kumar 2016-11-02 15:10:17 UTC
I have checked this issue with Xamarin.Forms 2.3.3-pre3 and observed that this issue is working fine.

Hence closing this issue.