我有一个 java 插件,可用于我开发的简单 java 应用程序。这个插件启动了一个也使用网络的新线程。
执行的类正在实现 Runnable 并以这种方式启动线程:
AsyncTask.execute(this);
这适用于 java 应用程序并且运行没有任何问题,但是,当我尝试使用 Unity3D 运行这个插件时,它会抛出一个错误并且不会运行我的插件
在 Unity3D 中执行的代码:
var token="AbCd123456789";
var jo = new AndroidJavaObject("com.edealya.lib.AppayableUnityAdapter");
jo.Call("runApplayble",token);
runAppayable 方法是:
public void runAppayable(String token){
DeviceIdentifier edDevice = new DeviceIdentifier(
this.getApplicationContext(),token);
edDevice.update();
}
和 edDevice.update(); 是启动新线程的方法。
I/Unity (27624): Exception: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
I/Unity (27624): at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <filename unknown>:0
I/Unity (27624): at UnityEngine.AndroidJNISafe.NewObject (IntPtr clazz, IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <filename unknown>:0
I/Unity (27624): at UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity (27624): at UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) [0x00000] in <filename unknown>:0
I/Unity (27624): at ReflectionFx.startAppayable () [0x00006] in /Users/Shared/Unity/4-0_AngryBots/Assets/Scripts/Fx/ReflectionFx.cs:30
I/Unity (27624): at ReflectionFx.Start () [0x00000] in /Users/Shared/Unity/4-0_AngryBots/Assets/Scripts/Fx/ReflectionFx.cs:38
我该如何解决这个问题?