And the following source code is the Java method who it will recieve the Activity.
public static void Test(Activity currentActivity)
{
// Doesn't get here at all
}
If I change the parameter Activity in the Java method by String, int and so on, the code works well but if I change it by an Activity, the java invocation doesn’t work.
Your code looks OK, but you didn’t post all of it, so hard to say. I suggest turning on JNI debugging. Add this line at the startup of your main scene (before any other JNI calls are made):
AndroidJNIHelper.debug = true;
This should output very detailed logs of exactly what’s happening behind the scenes of the JNI calls.
Tetsjava.lang.NSuchMethodError: no static method match with name=‘Test’ signature=‘(Loomunity3d.player.UnityPlayerActivity;)V’ in class
I don’t know what happened with my code, but I think that it’s something with casting or parsing a variable of type Activity to UnityPlayerActivity, but I’m not sure about it
This means that the JNI method lookup is invariant. Which seems to me extremely naive, but what do I know. Let’s try getting the method ID and calling that method directly. In your C# code do this (code not tested, slight modifications may be required):
IntPtr pluginClassPtr = pluginClass.GetRawClass(); // May need change GetRawClass to GetRawObject, but try it like this first
IntPtr methodPtr = AndroidJNIHelper.GetMethodID(pluginClassPtr, "Test", "(Landroid.app.Activity;)V", true );
AndroidJNI.CallStaticVoidMethod(pluginClassPtr, methodPtr, AndroidJNIHelper.CreateJNIArgArray(new object[] {activity}));
This code tries to use more basic JNI calls to force the method call to happen, even though the types don’t match exactly. May need to be tweaked a bit to actually work, since I never needed to drop down to that lower-level. But it conceptually should work.
Thank you vladimirg! I’m going to change my code with your advices but, Why does it not work my code well? I’ve seen some people doing exactly the same than me, and theirs codes work well for them .
I don’t know if it’s something with the manifiest, the ADT (or Eclipse) configuration or something else.
When I finished to do your recommendations I’ll come back to post if It works or not my code.
The code you posted uses GetRawObject(), did you try GetRawClass() as well? Did you inspect the IntPtr objects to have normal-looking pointers (not nulls or whatever)?
Yes, I used both (GetRawObject and GetRawClass) and I checked the pointers too. I don’t know what’s going on, Have you ever done a Java plugin for Unity3D before? I need some advices with my code :S