Good day , how can I implement the functions below? on xamarin
public IntPtr Handle => throw new NotImplementedException();
public int JniIdentityHashCode => throw new NotImplementedException();
public JniObjectReference PeerReference => throw new NotImplementedException();
public JniPeerMembers JniPeerMembers => throw new NotImplementedException();
public JniManagedPeerStates JniManagedPeerState => throw new NotImplementedException();
CodePudding user response:
Your C# object in the Android project should inherit from Java.Lang.Object
.
public class YourCSharpObject : Java.Lang.Object
{
}
CodePudding user response:
In xamarin, if we implement interface, we need to inherit from class Java.Lang.Object
as well as the interface itself,just as Trevor Balcom mentioned.
Suppose your interface is ITestClientListener
,we can do like this:
public class TestClientListener : Java.Lang.Object, ITestClientListener
{
public JniManagedPeerStates JniManagedPeerState()
{
throw new NotImplementedException();
}
IntPtr ITestClientListener.Handle()
{
throw new NotImplementedException();
}
int ITestClientListener.JniIdentityHashCode()
{
throw new NotImplementedException();
}
JniPeerMembers ITestClientListener.JniPeerMembers()
{
throw new NotImplementedException();
}
JniObjectReference ITestClientListener.PeerReference()
{
throw new NotImplementedException();
}
}
And we can use it's instance like this:
//create a new object
TestClientListener listener = new TestClientListener();
// use it as you need
Note:
You need to add necessary codes in above methods in class TestClientListener .cs
if it required.