I created simple plugin for opening Android Activity from Unity3D. Have problem to trigger method with parameters. Any ideas?
Java Code
public static void Show(Activity activity, String value, String value2)
{
Intent myIntent = new Intent(activity, DisplayAllUnits.class);
myIntent.putExtra("key1",value);
myIntent.putExtra("key2",value2);
activity.startActivity(myIntent);
}
and in onCreate
//load units for All Units placement from values
Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getString("key1");
value2 = extras.getString("key2");
}
a_id=value;
p_id=value2;
C# code to trigger it:
var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
var jc = new AndroidJavaClass("secret.package;)but.it.s.correct");
string value = "121";
string value2 = "1400";
jc.Call("Show", jo, "121", "1400");
And what is a problem: -without parameters, works, with parameters I have following error:
I/Unity: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
You're calling Call
, which is meant to call an instance method. You want CallStatic
, which calls a static method.
See more on this question at Stackoverflow