Bug 44160 - Android/Forms OnDisappearing firing minimized
Summary: Android/Forms OnDisappearing firing minimized
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 2.3.2
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-09-09 21:26 UTC by Andrew
Modified: 2017-01-04 15:56 UTC (History)
7 users (show)

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


Attachments
sample (1.01 MB, application/zip)
2016-09-12 14:09 UTC, Andrew
Details

Description Andrew 2016-09-09 21:26:08 UTC
Unlike in iOS Forms, Android Forms the OnDisappearing method is fired when the application is minimized (foreground - background). In some cases, if I remember which ones the OnAppearing does not get called then it is returned to the foregound causing the OnAppearing code to never run.

iOS: onDisappearing is fired when the page is removed from the stack.  Never gets fired any other times.
Comment 1 adrianknight89 2016-09-10 22:12:08 UTC
The question is which one is incorrect? Shouldn't iOS fire appearing and disappearing events when the app is backgrounded or foregrounded?
Comment 2 Andrew 2016-09-11 19:27:04 UTC
My preference be to fire it like iOS.  when the page is pushed or popped from the stack or in the tabbedPage to have it fire when tabs are changed.  

I will get a sample for Android.  I have code to prevent onDisappearing from Firing if the application is "Paused" (foreground to background) from removing Event handlers. The issue is the onDisappearing is a ran and OnAppearing it not always run when the application returns.

** Sample pending ** should get one by early next week.
Comment 3 Andrew 2016-09-12 13:52:30 UTC
Uploading a sample.

Instructions:

Run Sample on Android
Click Push Page 2 (ToolbarItem)

First Load:
Message: Page1 Disappear (OK)
Message: Page2 Appear (OK)

minimize the application and switch to another app.  (set to background and select any app on phone to load it)

go back to the Sample app.

Messages:
Page2 Appear (OK)
Page1 Appear (bad. Page1 should not fire Appear as it not on the top of the Stack)
Page2 Disappear (bad.  Page2 is active. Page2 Appear and Disappear should not happen)

This is the wrong sequence of events.

Run Sample for Tabs Android Forms.

Click Push Page2.
Click Push Tab

Tab Message:
Tab2Page2 Appear (OK)
TabPage1 Appear (OK)
TabPage1 Disappear (WHY? wrong)
TabPage1 Appear (WHY 2 times?)
Tabpage2 Disappear (WHY?)

What I think should happen.
TabPage1 Appear
TabPage2 Appear

Nothing else should happen.  Unsure why this sequence of events was designed this way for TabbedPage on Android.  lots of unneeded events firing.

on iOS this does not happen.
Comment 4 Andrew 2016-09-12 13:56:05 UTC
There seems to be a serious issue with executing code on Forms Android when the Application is set from the background - foreground. I have 3 tickets open for weeks no one seem to want to fix.  

I get updates from github about wanting to add "RadioButtons" to Xamarin Forms.  This is a breaking bug that causing all types of problems with code executing and crashing of the application.  Should be more important that added a "RadioButton" control to xamarin forms.  code executing on ContentPage that should not be running.  

I got 3 other bugs relating to the background - foreground.  got knows if my "hacks" to avoid the app crashing will work long term.
Comment 5 Andrew 2016-09-12 14:09:35 UTC
Created attachment 17414 [details]
sample
Comment 6 adrianknight89 2016-09-12 17:22:49 UTC
PR 342 should fix the first issue. Please do not use DisplayAlert for demonstration purposes. For example, when you background the app, PR 342 ensures that you get:

- Page2 Disappear
- come back to app
- Page2 Appear

If you use DisplayAlert, you get:
- Page2 disappear alert (has not been dismissed yet)
- come back to app
- Page2 appear alert

Now you will need to dismiss Page2 appear alert first and then Page2 disappear alert.

As for the tabpage, also remove DisplayAlert and retest and recreate steps. I noticed that TabPage1 fires appear, disappear, and appear the first time you navigate to it. For that, (I think) there should be another bug report.
Comment 7 Andrew 2016-09-12 18:28:31 UTC
Thanks for your fix :)  I post bugs and email support@xamarin.com to get these things fixed but go weeks without anything being done.  I will create another for TabPage.  I reference this bug.
Comment 8 Andrew 2016-11-30 02:17:34 UTC
What version is this bug fixed in? I have not seen the fix in any of the stable releases. I would like to test the fix.
Comment 9 Andrew 2016-11-30 16:35:47 UTC
Tabs have been fixed.


this has not been fixed in Xamarin Forms version 2.3.3.168:

Run Sample on Android
Click Push Page 2 (ToolbarItem)

First Load:
Message: Page1 Disappear (OK)
Message: Page2 Appear (OK)

minimize the application and switch to another app.  (set to background and select any app on phone to load it)

go back to the Sample app.

Messages:
Page2 Appear (OK)
Page1 Appear (bad. Page1 should not fire Appear as it not on the top of the Stack)
Page2 Disappear (bad.  Page2 is active. Page2 Appear and Disappear should not happen)
Comment 10 Rui Marinho 2016-11-30 18:02:00 UTC
The fix is in 2.3.4-pre1
Comment 11 Rui Marinho 2017-01-04 15:56:21 UTC
The fix is in 2.3.4-pre1

Note You need to log in before you can comment on or make changes to this bug.