Bug 25368 - Overriding OnStart () of Android.Support.V4.App.DialogFragment prevents the DialogFragment from being displayed
Summary: Overriding OnStart () of Android.Support.V4.App.DialogFragment prevents the D...
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 5.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jon Dick
Depends on:
Reported: 2014-12-14 13:16 UTC by Benjamin Broll
Modified: 2014-12-19 08:16 UTC (History)
2 users (show)

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:

Description Benjamin Broll 2014-12-14 13:16:58 UTC
Simply overriding the OnStart () method of Android.Support.V4.App.DialogFragment (even if it only contains the base-call) will prevent the DialogFragment from showing up on screen. A sample project has been uploaded to Github showing the problem:


The code in its original form will not show the DialogFragment. If the OnStart () method is removed from MainActivity.cs / MyDialogFragment class, however, the dialog shows up correctly.

This has been tested on the latest stable Xamarin.Android version as of 14 December 2014.
Comment 1 Benjamin Broll 2014-12-14 13:22:49 UTC
I should've added that this only applies to Android 5.0, we could *neither* reproduce this issue on Android 2.3 *nor* on Android 4.x.
Comment 2 Rajneesh Kumar 2014-12-15 07:50:38 UTC
I have checked this issue and able to reproduce. to reproduce this issue I have followed the help and instruction provided in bug description:

Steps I followed:

1. Open attached test case in XS.
2. Open MainActivity.cs file and comment the following line:
     public override void OnStart ()
			base.OnStart ();
3. Build and deploy the application on API 21 emulator.
4. It deploy and click on button.
5. Observed that the DialogFragment does't display.

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

I also observed that If I removed the OnStart() method from "MyDialogFragment" class, then the dialog shows up correctly.

Environment Info:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		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)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 7244769
Build date: 2014-12-11 14:54:30-0500

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 Jonathan Pryor 2014-12-18 19:34:06 UTC
@Redth: Please recompile the Xamarin.Android.Support.v4.dll assembly with a more recent Xamarin.Android release, something after Xamarin.Android 4.14.0.

I believe the problem here is that Fragment.OnStart() is "mis-bound", along the lines of Bug #17630. In this particular case, what happens is that `base.OnStart()` causes the "closest bound C# method" to be invoked. Since DialogFragment doesn't override Fragment.OnStart(), the C# `base.OnStart()` invokes Fragment.OnStart().

This is wrong because Fragment.OnStart() directly invokes Fragment.onStart(), thus causing us to "skip" DialogFragment.onStart():

> [Register ("onStart", "()V", "GetOnStartHandler")]
> public virtual void OnStart ()
> {
> 	if (Fragment.id_onStart == IntPtr.Zero) {
> 		Fragment.id_onStart = JNIEnv.GetMethodID (Fragment.class_ref, "onStart", "()V");
> 	}
> 	if (base.GetType () == this.ThresholdType) {
> 		JNIEnv.CallVoidMethod (base.Handle, Fragment.id_onStart);
> 	}
> 	else {
> 		JNIEnv.CallNonvirtualVoidMethod (base.Handle, this.ThresholdClass, Fragment.id_onStart);
> 	}
> }

(as obtained from the Xamarin Studio decompiler.)

What we see here is that id_onStart corresponds to Fragment.onStart(), and in a "base invocation" (when `GetType() != this.ThresholdType`) we reuse id_onStart for the CallNonvirtualVoidMethod() invocation, meaning (in this case) we SKIP DialogFragment.onStart()!

Re-generating the Xamarin.Android.Support.v4.dll binding (along with the others!) against Xamarin.Android 4.14 or later should fix this.
Comment 4 Jon Dick 2014-12-18 19:49:20 UTC

Please update your component, this is a very old version.  You are using 4.18.0 and the latest stable is 21.0.3.  You can get this from the component store, or NuGet.

Comment 5 Jon Dick 2014-12-18 20:05:32 UTC
I can confirm that this repro actually works properly with the Xamarin.Support.v4 component/nuget (version 21.0.3) on my Lollipop (API Level 21) device.
Comment 6 Benjamin Broll 2014-12-19 02:14:03 UTC
Hi Jon,

Is there any plan to update the component in the component store or should the general rule of thumb be to use the support packages from Nuget?

Cheers, Ben
Comment 7 Jon Dick 2014-12-19 08:16:31 UTC
Hi Benjamin,

The component in the component store has been updated already.  You'll have to remove the current version you have in the project, and then go add it again which should bring in the latest version (which actually just adds the nuget package itself).

If you don't need the samples from the component, it's definitely safe to go grab the nuget directly (we'll be always updating the NuGet first as the component itself now depends on this nuget package).