1

I am trying to write a interface callback from a java library inside Xamarin using c#, Below is the code snippet,

Connector.getInstance().login(email, new ILoginCallback() {
@Override
public void onSuccess(long heloUserId) {
/* call the required Activity for successful login */
}
@Override
public void onPinverification() {
/*call the Pin verification activity to validate pin */
}
@Override
public void onFailure(String description) {
/*show the toast msg for failure*/
}
});

I am unable to do interface callback in c# which blocked me to get the success or failure result.

Any Help appreciated.

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
user6352350
  • 13
  • 1
  • 5

2 Answers2

1

Implement your interface on a class that inherits from Java.Lang.Object:

public class MyLoginCallback : Java.Lang.Object, ILoginCallback
{
   // implement the interface
}

And then use that C# class that also now has a Android Callable Wrapper (ACW) as your callback instance.

Something like:

Connector.Instance.Login(email, new MyLoginCallback();

Re: Android Callable Wrappers

SushiHangover
  • 73,120
  • 10
  • 106
  • 165
  • Thanks for your response. Unfortunately but the code is still not working. Can you please elaborate more. – user6352350 Dec 10 '17 at 12:01
  • I did something like this, public partial class HeloLogin : ContentPage { private void OnRegister(object sender, EventArgs e) { Connector.Instance.Login(Email.Text, new XYZ()); } } public class XYZ : Java.Lang.Object, ILoginCallback { public void Dispose() { } public void OnFailure(string p0) { } public void OnPinverification() { } public void OnSuccess(long p0) { } } – user6352350 Dec 10 '17 at 12:06
  • @user6352350 That is not telling me what is not "working" – SushiHangover Dec 10 '17 at 12:08
  • I placed breakpoints on each method. but nothing gets hit after callback line executed. – user6352350 Dec 10 '17 at 12:09
  • @user6352350 You would need to debug whatever `Connector.Instance.Login` does... I would have no idea what it does or what Java library is bound. – SushiHangover Dec 10 '17 at 12:10
  • Can you please skype on anuragc64 ? – user6352350 Dec 10 '17 at 12:14
  • @SushiHangover, I implemented the interface as you said. It throws error when the callback in Android binding trying to execute my callback as **System.NotSupportedException Message=Unable to activate instance of type myapppackage.Droid.MyCallback from native handle 0xAxyz (key_handle 0xyue736)** – Thamarai T Oct 02 '21 at 12:47
  • @ThamaraiT post a new question with your code – SushiHangover Oct 03 '21 at 02:55
  • @SushiHangover, [question is already here](https://stackoverflow.com/questions/48420680/how-to-implement-ipay88-payment-gateway-sdk). Kindly refer this. – Thamarai T Oct 04 '21 at 05:54
1

Implement your interface as like below

public class MyLoginCallback : Java.Lang.Object, ILoginCallback, ISerializable
{    
   public MyLoginCallback()
   { }

   public MyLoginCallback(IntPtr intPtr, Android.Runtime.JniHandleOwnership handleOwnership)
   { }

   // implement the interface methods here
}
Thamarai T
  • 252
  • 1
  • 6
  • 19