Java .class operator support in JNI/JNIEnv ?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Java .class operator support in JNI/JNIEnv ?

Samus Arin
This post was updated on .
EDIT: Sorry, I mean "literal" http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.8.2

Using JNI/JNIEnv, is it possible to execute the second statement (.class operator) ?

    Class[] paramTypes= new Class[1];
    paramTypes[0]= String.class;

If so, and anyone knows of the top of their head, could I maybe see a quick sketch please ?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Samus Arin
This post was updated on .
        IntPtr ptrSystemProperties = JNIEnv.FindClass("android/os/SystemProperties");
        IntPtr method = JNIEnv.GetStaticMethodID(ptrSystemProperties, "get", "(Ljava/lang/String;)Ljava/lang/String;");

        System.IntPtr ptrResults = JNIEnv.CallStaticObjectMethod(SystemProperties.Handle, method,
                 //new Android.Runtime.JValue[]{ new Android.Runtime.JValue(new Java.Lang.String("bt.version.driver")) });
                 new Android.Runtime.JValue[]{ new Android.Runtime.JValue(new Java.Lang.String("debug.mono.extra")) });

        var tmpRet = Java.Lang.Object.GetObject<Java.Lang.String>(ptrResults, JniHandleOwnership.TransferLocalRef);
        return (string)tmpRet;
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Jonathan Pryor-2
In reply to this post by Samus Arin
On Sep 27, 2013, at 12:33 PM, Samus Arin <[hidden email]> wrote:
> Using JNI/JNIEnv, is it possible to execute the second statement (.class operator) ?

The `.class` operator is equivalent to the C# `typeof` operator. Depending on what you need to do with it, you can either use typeof(T) directly, or you can go through typeof() + Java.Lang.Class.FromType():

        var paramTypes = new Java.Lang.Class[]{
                Java.Lang.Class.FromType(typeof(Java.Lang.String)),
        };

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Jonathan Pryor-2
In reply to this post by Samus Arin
On Sep 27, 2013, at 4:56 PM, Samus Arin <[hidden email]> wrote:
> After all this work, the property debug.mono.extra doesn't even exist,

Why are you checking for the debug.mono.extra property? It's cleared by the debugger as part of startup; even if you did see it as a non-empty string, it wouldn't remain non-empty for long...

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Samus Arin
This post was updated on .
(ref: http://mono-for-android.1047100.n5.nabble.com/Debugging-a-service-in-another-process-td5712378.html)

It was over a year ago now, but support had suggested to try to either clear the mono.debug.extra field entirely, or increase the timeout value (to 5 or 10 sec) as an attempt to get the debugger to connect at deploy-time to an app that has more than one process.

My app has a service that runs in its own process b/c it calls Thread.Sleep often on the many threads it hosts, and I find if I call this on a thread running in the main app, then the UI thread goes to sleep as well....

I'm open to suggestions, Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Samus Arin
This post was updated on .
In reply to this post by Jonathan Pryor-2
"After all this work, the property debug.mono.extra doesn't even exist, "

I'm sorry, you found my message before I had a chance to edit it...

I was looking for mono.debug.extra in the system properties (build.prop), and soon after it dawned on my that each app/process may have its own poperty set (just like a command shell get its own environment), and removed that line from the post when I found it!
Reply | Threaded
Open this post in threaded view
|

Re: Java .class operator support in JNI/JNIEnv ?

Samus Arin
This post was updated on .
In reply to this post by Jonathan Pryor-2
After re-reading your suggestions about increasing the timeout value, or delaying the start of the activity, it dawned on me to set a breakpoint anywhere before the service is launched, and this works now.

I can't imagine not doing this in my previous attempts, but it's definitely possible.

Its been a long year of tracking bugs with print-outs!

Thanks.