[英]How to callback the Application Layer file from Native Layer file in a Android?
I have below three files in my Android project (one java file in Application layer, one cpp file in JNI layer & one cpp file in Native layer). 我的Android项目中有以下三个文件(“应用程序”层中的一个Java文件,“ JNI”层中的一个cpp文件和“本机”层中的一个cpp文件)。
I am able to call a api in Native Layer from Application Layer using JNI interface. 我可以使用JNI接口从应用程序层在本机层中调用api。
Is there a way through which I can have a callback to the Application Layer file (MyActivity.java) from Native Layer file (MyNativeFile.cpp)? 有没有一种方法可以使我从本机层文件(MyNativeFile.cpp)回调到应用程序层文件(MyActivity.java)?
Please share some sample code. 请分享一些示例代码。
Android fully implements standard JNI (except JNI_CreateJavaVM()
), so callbacks are supported. Android完全实现了标准JNI( JNI_CreateJavaVM()
除外),因此支持回调。 Note that you must attach your thread to JVM if you want to call Java back from a thread that was not started in Java (eg UI thread does not need AttachCurrentThread() ). 请注意,如果要从不是在Java中启动的线程回叫Java(例如,UI线程不需要AttachCurrentThread() ),则必须将线程附加到JVM。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.