Bug 29730

Summary: [XA 5.1] Event handlers subscribed to (some?) events that are bound to Java callbacks no longer work
Product: Android Reporter: Brendan Zagaeski (Xamarin Team, assistant) <brendan.zagaeski>
Component: GeneralAssignee: dean.ellis
Status: VERIFIED FIXED    
Severity: major CC: eric.schmeck, heavycrag, jonp, m.fegerl, mikhail.melnik, mono-bugs+monodroid, prashantm, steve, udhams
Priority: High    
Version: 5.1   
Target Milestone: 6.0 (C6)   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Test case
Logcat and diagnostic build output

Description Brendan Zagaeski (Xamarin Team, assistant) 2015-05-04 22:37:21 UTC
Created attachment 11065 [details]
Test case

[XA 5.1] Event handlers subscribed to (some?) events that are bound to Java callbacks no longer work.


This might be related to how `Java.Interop.EventHelper.AddEventHandler()` works behind the scenes?


Regression status: REGRESSION between XA 4.20 and XA 5.1 (d23da36)



## Steps to reproduce

Build and run the attached test case on emulator or device.

(The test case is just a new template app that adds an event handler on `button.ViewTreeObserver.GlobalLayout`.)




## Actual results

A. The app does _not_ run `Button_ViewTreeObserver_GlobalLayout()`.

B. The application output does _not_ show the `Console.WriteLine()` output.




## Expected results

A. On Xamarin.Android 4.20, the app _does_ run `Button_ViewTreeObserver_GlobalLayout()`.

B. The application output _does_ show the `Console.WriteLine()` output:
> ### GlobalLayout even handler called




## Version information

### Android devices

Xamarin Android Player 0.3.7 (1), Nexus 4 (KitKat)


### OS X 10.9.5, MacBook Air

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: 2c0ea975-8f73-4920-8414-3e9ae359fbf4
Runtime:
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Xamarin.Android ===

Version: 5.1.0.115 (Business Edition)
Android SDK: /Users/macuser/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)
Java SDK: /Users/macuser
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-05-04 22:38:03 UTC
Created attachment 11066 [details]
Logcat and diagnostic build output
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-05-04 22:39:25 UTC
## Workaround

Use the `button.ViewTreeObserver.AddOnGlobalLayoutListener()` method rather than the `button.ViewTreeObserver.GlobalLayout` event.

For a more complete example of that approach see [1].

> [1] https://github.com/xamarin/monodroid-samples/blob/1be38c07916d1fc30adfcd5247e141ea9daa5da2/GooglePlayServices/GooglePlayServicesTest/Source/MarkerDemoActivity.cs#L217
Comment 5 Jonathan Pryor 2015-05-05 17:14:18 UTC
> [XA 5.1] Event handlers subscribed to (some?) events that are bound to Java
> callbacks no longer work.

Does this happen for any other events, or just for the ViewTreeObserver.GlobalLayout event?

If it's just the ViewTreeObserver.GlobalLayout event, then you're probably hitting the fix for Bug #17257.
Comment 7 Jonathan Pryor 2015-05-05 17:33:03 UTC
*** Bug 17257 has been marked as a duplicate of this bug. ***
Comment 8 Jonathan Pryor 2015-05-07 15:41:37 UTC
Commits monodroid/35fe327c and monodroid-5.1-series/690e31db revert behavior to the previous Xamarin.Android 4.20 behavior, reintroducing Bug #17257.
Comment 9 Udham Singh 2015-05-08 07:10:31 UTC
I have checked this issue with Xamarin.Android 5.1.1.3 and observed that now 'Button_ViewTreeObserver_GlobalLayout()' is getting called and in application output we are getting '### GlobalLayout even handler called'.

Hence I am closing this issue. Screencast : http://www.screencast.com/t/43EUUtbiTYN

Environment Info : 

Mac OS X 10.9.5
Xamarin Studio 5.9.1 (build 3)
Mono 4.0.1 ((detached/88674ce)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.2 (6776)
Xamarin.Android 5.1.1.3 (Enterprise Edition)
Comment 10 Udham Singh 2015-05-08 07:12:56 UTC
An update to the comment 9 : I have checked this issue with XAP 0.3.4(1) and NEXUS 5 (android 5.0.1) and observed that this is working fine with both. Thanks!