Search Unity

startActivityForResult crashes program

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dev Chorus, Jun 8, 2015.

  1. Dev Chorus

    Dev Chorus

    Joined:
    Nov 1, 2013
    Posts:
    5
    I'm trying to build an android sina weibo plugin for unity, and their authentication requires the calling activity to override onActivityResult. Since I'm passing in unity's activity as the context for the authentication, I will need to override the function on Unity's activity. However, I am reluctant to implement a custom Unity activity as this might cause other problems with the rest of my plugins.

    Instead, I have opted to create a middle-man activity which calls my authentication activity with startActivityForResult. The problem is that the problem stops working once the line of code is called. I have tried adding debug lines and try catch the block in logcat. No exceptions are getting thrown and I'm sure the function is being called, but the other activity is not getting started and the program just stops there.

    Here's the Unity c# codes

    Code (CSharp):
    1. public class weibo_manager : MonoBehaviour
    2. {
    3.  
    4.     AndroidJavaClass jc;
    5.     AndroidJavaObject activity;
    6.     AndroidJavaClass myJC;
    7.     AndroidJavaObject myJO;
    8.     public Text txt;
    9.     public Text debug;
    10.  
    11.     // Use this for initialization
    12.     void Start ()
    13.     {
    14.         try{
    15.             AndroidJNI.AttachCurrentThread();
    16.             jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    17.             activity = jc.GetStatic<AndroidJavaObject>("currentActivity");
    18.  
    19.             activity.Call("runOnUiThread", new AndroidJavaRunnable(runOnUiThread));
    20.  
    21.         }
    22.         catch(Exception e)
    23.         {
    24.             debug.text = e.Message;
    25.         }
    26.     }
    27.  
    28.     void runOnUiThread()
    29.     {
    30.         using (myJO = new AndroidJavaObject("com.sina.weibo.sdk.demo.WBResultAdapter"))
    31.         {
    32.             if (myJO != null)
    33.             {
    34.                 debug.text = "myJO not null";
    35.                 myJO.Call("init");
    36.             }
    37.             else
    38.             {
    39.                 debug.text += "myJO is null";
    40.             }
    41.         }
    42.     }
    43. }
    and here's the middle-man activity I'm calling

    Could anyone point me in the right direction? Is this due to some issue with passing Unity's context around or is there a better way to go about doing this?
     
  2. dpkstr

    dpkstr

    Joined:
    Feb 12, 2014
    Posts:
    3
    Did you find any solution for this?
     
  3. dpkstr

    dpkstr

    Joined:
    Feb 12, 2014
    Posts:
    3
    @dev-chorus
    Did you fin any solution for this?