theblitz
theblitz

Reputation: 6881

Callback to Unity is null

I have created a callback in Unity to enable me to send results back from an Android app to the Unity app. I prefer this to UnitySendMessage because it is much "cleaner".

I used the exact eample given here: Callback Listener in Unity - How to call script file method from UnityPlayerActivity in Android

Unity c# code:

public class MoviePlayer : MonoBehaviour {

// Use this for initialization
void Awake () {

    AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject activity = jc.GetStatic<AndroidJavaObject>("currentActivity");


    StartUpCallback startupCallback = new StartUpCallback();
    AndroidJavaObject control = new AndroidJavaObject("vrbridge.Control", activity);
    //control.Call("startUp");
    control.Call("startUp", startupCallback);

}

class StartUpCallback:  AndroidJavaProxy
{
    public StartUpCallback() : base("vrbridge.StartUpCallback") { }

    public void OnSuccess() { }
    public void OnFailure() { }
}
}

Android code:

public class Control implements LibraryManagerInitStartDialogFragment.ConfigurationFragmentListener{

String TAG = "QuickPlayTest";


private Activity _activity;
private StartUpCallback _startUpCallback;

public Control(){
    Log.d(TAG, "Constructor.");

}

public Control(Activity activity){
    Log.d(TAG, "Constructor. Activity = " + activity);
    _activity = activity;
}


public void startUp(StartUpCallback startUpCallback){
    Log.d(TAG, "startUp. Callback = " + startUpCallback);
    _startUpCallback = startUpCallback;
    new LibraryManagerInitStart(_activity, this);
    Log.d(TAG, "startUp - end");
}
}

public interface StartUpCallback {
    public void onSuccess();
    public void onFailure();
}

For some reason the parameter startUpCallback in startup() is always null.

I tried shifting it to the constructor with the same result. OTOH, the value of activity is okay.

Did I miss something?

Upvotes: 1

Views: 968

Answers (1)

Ed Marty
Ed Marty

Reputation: 39690

Perhaps the problem is that your C# proxy does not correctly implement the Java interface. Note the capitalization differences in the word "on/On".

Upvotes: 1

Related Questions