Bug 40527 - Xamarin.Android.Support.v4 App.ActivityOptionsCompat.ToBundle() always returns null
Summary: Xamarin.Android.Support.v4 App.ActivityOptionsCompat.ToBundle() always return...
Alias: None
Product: Components
Classification: Xamarin
Component: Xamarin Components ()
Version: Production (addons.xamarin.com)
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: Jon Dick
Depends on:
Reported: 2016-04-19 18:00 UTC by Jon Douglas [MSFT]
Modified: 2016-05-19 21:01 UTC (History)
4 users (show)

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

Reproduction (1.32 MB, application/x-zip-compressed)
2016-04-19 18:00 UTC, Jon Douglas [MSFT]

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 Jon Douglas [MSFT] 2016-04-19 18:00:14 UTC
Created attachment 15772 [details]


ActivityOptionsCompat.ToBundle() always returns null even when given a proper ActivityOptionsCompat argument. Using this same syntax below in Android Studio(Java) works fine with the Android.Support.v4 library:

                var options = ActivityOptionsCompat.MakeSceneTransitionAnimation(this, button, "Transition_Popup");
                var optionsBundle = options.ToBundle(); //optionsBundle is always null

I have checked many versions of the support v4 library in which this seems to not work as of:

Xamarin.Android.Support.v4 23.3.0
Xamarin.Android.Support.v4 23.2.1

Thus I believe this is a bug and should be fixed as the current workaround involves creating a Java Binding "Wrapper" of this, to invoke correctly.


    public Bundle sharedElementBundle(Activity activity, View view, String sharedelemname)
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, view, sharedelemname);
        return options.toBundle ();

    public Bundle sharedElementBundle(Activity activity, Pair<View, String> sharedelems)
        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation (activity, sharedelems);
        return options.toBundle ();

*Reproduction Steps:

1. Download reproduction titled "ToBundleNull.zip"
2. Open the .sln
3. Set a breakpoint on line #34 or known as "var optionsBundle = options.ToBundle();"
4. Run the program, hit the button and notice the bundle is null

*Version Information:

Microsoft Visual Studio Professional 2015
Version 14.0.25123.00 Update 2
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Professional

Xamarin (0dd817c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (a94a03b)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (3a25bf1)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Jeremy Kolb 2016-04-27 18:05:18 UTC
I can reproduce this.
Comment 2 Jeremy Kolb 2016-04-27 18:47:00 UTC
See this thread for others who have hit this https://forums.xamarin.com/discussion/61209/shared-element-not-working
Comment 3 Jon Dick 2016-05-11 01:02:12 UTC
This is an over-simplified version of the actual code, but I wanted to brain dump it here as part of the discussion:

The ActivityOptionsCompat.toBundle returns null.  The ActivityOptionsImplJB.toBundle does not.  On API Level >= 16, the ActivityOptionsImplJB is used.

  public class ActivityOptionsCompat
    public static ActivityOptionsCompat makeCustomAnimation ()
      if (Build.VERSION.SDK_INT >= 16) {
        return new ActivityOptionsImplJB();

      return new ActivityOptionsCompat();

    public Bundle toBundle()
      return null;

    private static class ActivityOptionsImplJB extends ActivityOptionsCompat
      public Bundle toBundle()
        return this.mImpl.toBundle();
Comment 4 Jon Dick 2016-05-11 15:16:12 UTC
So the reason this was happening is the ActivityOptionsImpl21 and ActivityOptionsImplJB classes had bindings generated for them (they should be removed), so the wrong ToBundle() was being called and always returning null.

This will be fixed in or higher