Android switch activity from unini

I am working on an android unity3d project where I want to post material on facebook. Basically, the application launches activity that is beyond my control. A single sign-in to Facebook requires me to provide activity in order to show it. Now the problem is that the trigger for publishing to facebook is sent from Unity activity (from native code via JNI). its basically my simple java object as a connector that is created from unity in native code, and I can call it methods. I also have an available link to currentActivity. There are still problems to do something about it.

I always get

AndroidRuntime(12845): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 

I tried to specify this current activity link for authorize () as activity for binding, but gives an error. I tried to switch to my own activities, where I wanted to launch Facebook. got the same error. tried it

 Intent intent = new Intent(UnityPlayer.currentActivity.getApplicationContext(), MyActivity.class); UnityPlayer.currentActivity.startActivity(intent); 

also few other similar things, but simply can’t switch activity. How should I do it?

thanks

+4
source share
1 answer

This is because the user interface operation cannot be performed on the workflow. You should try runOnUiThread .

 UnityPlayer.currentActivity.runOnUiThread(new Runnable() { public void run() { Intent intent = new Intent(UnityPlayer.currentActivity.getApplicationContext(),MyActivity.class); UnityPlayer.currentActivity.startActivity(intent); } }); 
+7
source

Source: https://habr.com/ru/post/1394928/


All Articles