Bug 32615

Summary: [Android] OnAppearing is not called on previous page when modal page is popped
Product: Forms Reporter: Michael <michael.watson>
Component: FormsAssignee: Rui Marinho <rui.marinho>
Status: RESOLVED FIXED    
Severity: normal CC: anderson.jacobd, arpitj, chris.king, chris.wei.hu, david, eric.maupin, jas, michael.osborn, parmendrak, rui.marinho, seth.rosetter, zstarkebaum
Priority: Normal    
Version: 1.4.4   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: ac Is this bug a regression?: ---
Last known good build:
Attachments: Reproduction

Description Michael 2015-07-30 11:31:22 UTC
Steps to reproduce:
1. Create new Forms project
2. Add the two XAML pages with the following code:

Page 1 XAML
	<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 	x:Class="OnAppearingTest_Microsoft.Page1">
		<StackLayout HorizontalOptions="Center" VerticalOptions="Center">
			<Label x:Name="TextField" />
			<Button Clicked="Button_OnClicked" Text="Click"/>
		</StackLayout>
	</ContentPage>

Page 1 code behind
	public partial class Page1 : ContentPage
	{
		private int _counter;
		public Page1 ()
		{
			InitializeComponent ();
		}

		private async void Button_OnClicked(object sender, EventArgs e)
		{
			await Navigation.PushModalAsync(new Page2());
		}

		protected override void OnAppearing()
		{
			//Refresh Contents in page
			TextField.Text = _counter++.ToString();
		}
	}

Page 2 XAML
	<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="OnAppearingTest_Microsoft.Page2">
		<StackLayout HorizontalOptions="CenterAndExpand"
			VerticalOptions="CenterAndExpand">
			<Button Clicked="Button_OnClicked"
				Text="Go Back"/>
		</StackLayout>
	</ContentPage>

Page 2 code behind
	public partial class Page2 : ContentPage
	{
		public Page2 ()
		{
			InitializeComponent ();
		}

		private async void Button_OnClicked(object sender, EventArgs e)
		{
			await Navigation.PopModalAsync(); //Not Working – Does not trigger OnAppearing() in page1
		}
	}

3. Run the application
4. Label should display 0
5. click the button to push the modal
6. click the button on the modal page to pop the modal.

Expected Results:
OnAppearing should be called when Page2 modal is popped and Page1 appears. Label should display 0 and switch to 1 when the page appears.

Observed Results:
OnAppearing is never called.

I have tested this to work as expected on iOS.

*****System Info*********
Xamarin Studio
Version 5.9.5 (build 6)
Installation UUID: 79a7cdf3-cf91-4206-8668-4654a92d0c83
Runtime:
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

Xamarin.Android
Version: 5.1.5.3 (Enterprise Edition)
Android SDK: /Users/michaelwatson/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

Xamarin Android Player
Version: Unknown version
Location: /Applications/Xamarin Android Player.app

Apple Developer Tools
Xcode 6.3.2 (7718)
Build 6D2105

Xamarin.iOS
Version: 8.11.0.1232 (Enterprise Edition)
Hash: 26c6349
Branch: master
Build date: 2015-07-16 11:18:45-0400

Xamarin.Mac
Version: 2.0.2.102 (Enterprise Edition)

Build Information
Release ID: 509050006
Git revision: c50b1022a6b36f9b2a55beb7814b87811d1dba52
Build date: 2015-07-16 18:13:13-04
Xamarin addins: 6571e3228ff9e432a98b468630ec5ffd35f2f6b3

Operating System
Mac OS X 10.10.3
Darwin Michaels-MacBook-Pro-2.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Chris King 2015-07-31 13:19:05 UTC
Created attachment 12318 [details]
Reproduction

Reproduction
Comment 2 Arpit Jha 2015-08-06 07:12:02 UTC
I have checked this issue and able to reproduce with the help of bug description and attached project.

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

Environment Info:
Xamarin.Forms version: 1.4.4.6392
=== Xamarin Studio ===

Version 5.9.5 (build 7)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 4.0.3 ((detached/102a681)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400030018

=== Xamarin.Android ===

Version: 5.1.5.3 (Enterprise Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.10.4.45 (Enterprise Edition)
Hash: b94bc00
Branch: master
Build date: 2015-08-04 15:26:49-0400

=== Xamarin.Mac ===

Version: 2.0.2.35 (Enterprise Edition)

=== Build Information ===

Release ID: 509050007
Git revision: 676dac8a7ae1d4e6de624a0e029ae141cbc59028
Build date: 2015-07-22 13:25:06-04
Xamarin addins: d53d6eceb828422f3d4aff8547f2f6bab6c9ea58

=== Operating System ===

Mac OS X 10.10.4
Darwin mac360-xamarins-Mac-mini.local 14.4.0 Darwin Kernel Version 14.4.0
    Thu May 28 11:35:04 PDT 2015
    root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
Comment 3 Rui Marinho 2016-01-20 11:50:43 UTC
Should be fixed in 2.1.0-pre1
Comment 4 Parmendra Kumar 2016-01-22 14:08:15 UTC
I have checked this issue with Xamarin.Forms version 2.1.0.6503-pre2 and I am still getting same behavior mentioned in bug description. To verify this issue I am using sample project attached in comment #1.

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

ApplicationOutput: https://gist.github.com/Parmendrak/a084d33ae6340e521577

Hence reopen this issue.

@Rui, Please have a look and let me know If I have missed anything to check this issue.

Thanks.
Comment 5 anderson.jacobd 2016-01-27 02:07:01 UTC
Since this bugs status is reopened. I noticed that it calls the MainPage.OnAppearing(), but not the page on top's OnAppearing().

1.) Create a NavigationPage and set a MainPage 
2.) Push a 2nd page on-top async.
3.) Push a 3rd page async and Modal
4.) Pop the 3rd page off async and Modal
5.) On Android: MainPage's OnAppearing is called but not page 2's even though that is the page being displayed.
Comment 6 Jason Smith [MSFT] 2016-04-11 09:48:31 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.

I believe this was fixed in 2.2.0 in particular.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team
Comment 7 chris hu 2016-11-11 01:17:50 UTC
Confirm fixed in Xamarin.form nugget 2.3.2