android从非ui线程切换活动
我正在开发 android unity3d 项目,我想在 Facebook 上发布一些内容。 基本上,该应用程序正在运行不受我控制的活动。 Facebook 单点登录要求我提供活动来显示其内容。 现在的问题是,发布到 facebook 的触发器是从 Unity 活动中发出的(从本机代码通过 JNI)。它基本上是我的普通 Java 对象作为连接器,它是从本机代码中统一创建的,我可以将其称为方法。我还可以访问 currentActivity 的参考。仍然很难用它做任何事情。
我总是得到
AndroidRuntime(12845): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
我尝试将当前活动引用 Facebookauthorize() 作为要绑定的活动,但给出了错误。 我尝试切换到我自己的活动,我想在上面启动 Facebook。 得到同样的错误。 也尝试
Intent intent = new Intent(UnityPlayer.currentActivity.getApplicationContext(), MyActivity.class);
UnityPlayer.currentActivity.startActivity(intent);
过其他一些类似的事情,但只是无法切换活动。 我该怎么做?
谢谢
I'm working on android unity3d project where I want to post some stuff to facebook.
Basically the app is running activity which is out of my control. Facebook single sign on requires me to provide activity to show up its stuff.
Now the problem is that trigger to post to facebook is comming out from Unity activity (from native code through JNI). its basically my plain Java object as connector which is created from unity in native code and I can call it methods. I have also accessible reference to currentActivity. Still having troubles to do anything with it.
I always get
AndroidRuntime(12845): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
I tried to give this current activity reference to Facebook authorize() as activity to bind to but gives the error.
I tried to switch to my own activity where I wanted to start Facebook on it.
got the same error.
tried this
Intent intent = new Intent(UnityPlayer.currentActivity.getApplicationContext(), MyActivity.class);
UnityPlayer.currentActivity.startActivity(intent);
also few other similar things but just can't switch activity.
How should I do this?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这是因为 UI 操作无法在工作线程上运行。您应该尝试
runOnUiThread
。That is because UI operation cannot run on worker thread. You should try
runOnUiThread
.