Bug 24310 - Launching another AndroidActivity break navigation
Summary: Launching another AndroidActivity break navigation
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-11-06 12:55 UTC by Yann ROBIN
Modified: 2017-01-09 20:58 UTC (History)
5 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:
RESOLVED FIXED

Description Yann ROBIN 2014-11-06 12:55:27 UTC
Hi,

For one of our application page, we need the ActionBar (android) to be set has overlay.

To set ActionBar has overlay we must set the WindowFeature before the OnCreate.
As Xamarin.Forms use only one Activity, this would impact all our Page.

So we decided to launch a new AndroidActivity for the page that need the overlay.

When launching a new activity the navigation to the old navigation is broke.
This is due to a "bug" in Xamarin Forms code :

When creating a new AndroidActivity and doing SetPage, a new Platform is created.
In the created Platform there is an add to a static event (AndroidActivity.BackPressed) that is called when pressing back button.

So here it goes :
FirstActivity => Register on BackPressed
Tap on back button call FirstActivity function
SecondActivity => Register on BackPressed
Tap on back button call SecondActivity function
Kill SecondActivity => UNREGISTER IS NOT DONE
FirstActivity => Navigate
Tap on back button call SecondActivity function :/ (which has a stackdepth = 1 and kill application)


The fix would be to unregister the delegate on BackPressed when killing Activity.

If you can do that fix this week you would save us, I mean really. We have to ship our apps mid December and the biggest problem that we have is that our epub reading library NEED a new Activity.
Comment 1 Udham Singh 2014-11-07 07:36:39 UTC
Hi Yann,

We have tried to reproduce this issue but not able to reproduce this. Could you please provide a sample app/test case/steps in detail/screencast, so that we can reproduce this issue at our end and help to resolve this issue.

Also please provide your environment info. You can get environment info via

1. 'Help ->About Microsoft Visual Studio ->Copy Info and paste it' - In Visual Studio
2. 'Xamarin Studio ->About Xamarin Studio ->Show Details ->Copy Information and paste it' - In Xamarin Studio

Thanks
Comment 2 Yann ROBIN 2014-11-07 11:40:03 UTC
Hi Udham,

I've made an example from Forms2Native available here :
https://github.com/Youscribe/BugReportXamarinAndroidActivity

Test scenario :
Launch application on Android => MyFirstPage displayed
Click on "Click to see a native page" => MySecondPage displayed
Tap on back button => MyFirstPage displayed

then :
Click on "Click to see an Intent work" => MyThirdActivity displayed
Tap on back button => MyFirstPage displayed

(everyhting fine so far)
then :
Click on "Click to see a native page" => MySecondPage displayed
Tap on back button => Application is closed
Expected behavior : MyFirstPage displayed


Also in third activity I've commented a fix made using reflection (dirty dirty fix). If you uncomment it, it will unregister the Backpressed event when back is pressed.
Comment 4 Udham Singh 2014-11-12 08:55:27 UTC
I have checked this issue with the help of instructions provided in comment 2 and here are my observations :

1. When I click on button "Click to see a native page" second page is displayed with back button and by clicking on back button we can navigate back to the first page.

2. When click on "Click to see an Intent work" third page (MyThirdActivity) is displayed without back button and if we click on back button of emulator
then first page is displayed.

3. Again if we click on button "Click to see a native page" second page is displayed with back button and by clicking on back button we can navigate back to the first page successfully and Application does not close.

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

Could you please have a look on the screencast and let me know if I missed anything. 

Also please include Ide Log, Application Output and Android Device Log, We may have to see if developer can figure out what's going on from the stack trace.

You can get Ide Log via : 'Help->Open Log directory and get the latest IDE log', Device Log via : 'View->Pads->Android Device Log and choose device'.

Note : I have checked this issue with both emulator and device Samsung Galaxy S5(Android 4.4.2) and getting the same bahaviour with both.

Environment Info :

=== Xamarin Studio ===

Version 5.5.3 (build 6)
Installation UUID: 3235da96-1cb2-43d5-a836-234fd96911c2
Runtime:
	Microsoft .NET 4.0.30319.18449
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.18.1 (Enterprise Edition)
Android SDK: D:\Backup_OldMachine\D Drive\SDK\android-sdk
	Supported Android versions:
		1.6    (API level 4)
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.0    (API level 11)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		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)
		4.5    (API level 21)
Java SDK: C:\Program Files\Java\jdk1.7.0_67
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:11:11-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 5 Yann ROBIN 2014-11-12 09:00:48 UTC
The issue happens only with the "hardware" back button. In the screencast you are using the upper left back button and not the hardware button.
Comment 6 Udham Singh 2014-11-12 09:26:49 UTC
I have again checked this issue and observed that application is getting closed/crashed. To reproduce this issue I have followed the instructions provided in comment 2 and comment 5.

Screencast : http://www.screencast.com/t/5PM3Y8RjAA2

Application Output : https://gist.github.com/Udham1/97d434ebc3b97b92ad4a
Android device log(Emulator): https://gist.github.com/Udham1/5810533a17d53c264118
Android device log (Hardware): https://gist.github.com/Udham1/71f8ba168f84b2bfddbe
Ide Log : https://gist.github.com/Udham1/4cf3b585a58cd009d10b

Environment Info : Please refer comment 4.

Note : I have checked this issue with both emulator and device Samsung Galaxy
S5(Android 4.4.2) and observed that application is getting closed/crashed with both.
Comment 7 Jimmy [MSFT] 2017-01-09 20:58:07 UTC
I was able to reproduce the original issue with Forms 1.2.2 using the project linked to in comment 2. However I no longer experience the issue with Forms 2.3.3. In fact it seems to have been fixed since 1.3.0 as I cannot reproduce the issue starting with that version.