-
Notifications
You must be signed in to change notification settings - Fork 94
[Android] Calling into C# on a different thread fails #439
Comments
Thanks @Zomb I will look into this. Can you paste a snippet of your Java code? |
I tried two methods:
and
The C# library I am calling into is Mono.Android library. |
I'm seeing this, too. One workaround for now is to subclass I have this C#: [Register("mono.embeddinator.android.SubclassJava")]
public class SubclassJava : Java.Lang.Object { } Then my test in Java: @Test
public void thread() {
new Thread(() -> {
try {
SubclassJava obj = new SubclassJava();
obj.toString();
} catch (Throwable e) {
//apparently Java lambdas don't do checked exceptions
throw new RuntimeException(e);
}
}).start();
} This case works, but if it isn't I will research if this just needs to be a limitation or if it can be fixed. |
This method does work, and I have no crashes when I create a thread. In the process of testing this out a couple of days ago, I ran into a particular problem related to the Register attribute. If the specified package is in camel case (Register("MoNo.embed.SubclassJava")) then Android Studio had problems using the class. This has nothing to do with the thread though, and if I find more information on the problem, I will create a new issue! |
@jonathanpeppers I have a same issue, during Emebeddination process I am getting this Note: AndroidEmbeded.java uses unchecked or unsafe operations. Recompile with -Xlint:unchecked for details. However, my Embeddination is successfull and I am getting AAR file. In AAR file the AndroidEmbeded.java is accessble and I can create instance but Embeddination do not generates any methods which are present in AndroidEmbeded.java. @Zomb Were you able to generate all methods while inhereting from Java.Lang.Obj? |
@emysa341 did you find any solution to generate all methods while inheriting from Java.Lang.Obj? |
If you attempt to create an instance of the C# object in Android Studio inside a thread other than the main thread, using new Thread or AsyncTask, results in a crash with (some) of the trace seen below:
The text was updated successfully, but these errors were encountered: