1

I have a Xamarin.Android project. How can I use java class declared in java file from C# code? How can I reference to it?

That is what I did: 1) I've added java file to project, 2) set up build action to AndroidJavaSource 3) Compiled (and seen Foo.class in obj folder)

Foo.java

package x.y.z;
public class Foo{
}

How can I reference to Foo from C#?

var f = new Foo();
f.someFunction();

1 Answer 1

1

I've solved it!

Instance is created by

Java.Lang.Object obj = Java.Lang.Class.ForName("x.y.z.Foo").NewInstance();

You can cast Java.Lang.Object to a known ancestor if necessary.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.