Bug 26194 - Activity.SetResult expects parameter 1 to be Result-Enum
Summary: Activity.SetResult expects parameter 1 to be Result-Enum
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.20.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2015-01-20 05:30 UTC by Martin Kuckert
Modified: 2015-01-20 05:51 UTC (History)
1 user (show)

Tags:
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 FEATURE

Description Martin Kuckert 2015-01-20 05:30:03 UTC
The method signature of the android Activity method setResult is

  public final void setResult (int resultCode)

The Xamarin Android binding changes this to

  public void SetResult(Result resultCode)

This results in compatibilty issues if i'd like to use resultCode as an arbitrary integer resultCode. I'd like for example to return a page number as the resultCode. That's possible in my android code:

  setResult(mItems[position].page);

But fails for Xamarin with the error "Argument type 'int' is not assignable to parameter type 'Android.App.Result'".

Contrary to this the signature of the startActivityForResult is bound unchanged:

  Android: public void startActivityForResult (Intent intent, int requestCode)
  Xamarin: public virtual void StartActivityForResult(Intent intent, int requestCode);

I may change my Java implementation to use the setResult(Result resultCode, Intent data) method, but that's just a workaround.
Comment 1 Atsushi Eno 2015-01-20 05:45:45 UTC
This is inevitable. You need explicit cast to int.

If we change this signature from Result enum to int (which we will NOT do, because that brings API breakage), that causes other messes.

In early Mono for Android era from Novell, early developers converted ints to enums without covering "everything". It's partly done. There are some enums that are argurable to have been converted. Android.App.Result is typical "it's annoying without being converted to enum" "but some methods use resultCode/requestCode as int in common practice" "OK we apply best-appropriate one for each method" kind of enumification.

We could leave everything not-converted to enum, but that results in as annoying API as Java. There is not a LOT of required casts between ints and enums, so it is regarded as better than only-ints-based API.

This is by design.

You cannot change Java signature that Android framework expects.
Comment 2 Martin Kuckert 2015-01-20 05:51:11 UTC
I see the need to stay with the current binding to circumvent breaking any stuff.

Basically, searching for a solution for my problem, i'm able to use any integer value and passing this through the method by casting it to Result?

Especially for my case:
  SetResult((Result)mItems[position].Page);

I haven't tried this yet, i'm not that far. But will this work? Is this the intended solution to satisfy the Xamarin binding?