How to access from ndk activity created in java?

126 views
Skip to first unread message

Ilya Nesterov

unread,
Feb 2, 2018, 1:20:39 PM2/2/18
to android-ndk
Hi,

I'm playing around with native activity and android_native_app_glue. My current experiment is whether I can access from NDK an activity created from Java. 
So, it is more clear what is going on when you create a native activity, because when you implement android_main , android_app structure is created for you and passed to the android_main as a parameter.

My question is: If I create activity in Java, can I access the activity from native code through JNI? 

I think Ill need to create android_app structure manually but passing ANativeActivity* activity and AConfiguration* config and other stuff which might be accessible through JNIEnv *env. I want to reference current activity to catchAMotionEvent_* events.
is it possible? Am I going in the right direction?

Alex Cohn

unread,
Feb 4, 2018, 1:47:18 PM2/4/18
to android-ndk
I believe you are making your life too hard. NativeActivity is actually a Java class that alteady implements all hooks necessary to work with the android_native_app_glue. You can easily extend this Java class in Java, adding whatever you want. If you are careful, you will not have to touch the glue code on either side of JNI.

BR,
Alex
Reply all
Reply to author
Forward
0 new messages