简体   繁体   English

如何在Android上的JNI中实现委托/协议(在iOS上)?

[英]How to implement delegate/protocol(on iOS) in JNI on Android?

I'm building an aar library on Android, which is with JNI/C++ codes. 我正在用JNI / C ++代码在Android上构建aar库。 What I want to do is to pass an event (when the event happens, I want to pass it out) form C++ to Java application( the application which imports my aar library), and the application can then take care of the event. 我想做的是将一个事件(事件发生时,我想将其传递出去)从C ++传递给Java应用程序(导入我的aar库的应用程序),然后该应用程序可以处理该事件。 I've done the same thing on iOS with delegate/protocol, is there any equivalent that I can implement on JNI for the same purpose? 我在iOS上使用委托/协议做了同样的事情,出于相同的目的,我可以在JNI上实现任何等效功能吗? Thanks a lot! 非常感谢!

I'm unsure exactly what features of iOS delegate you want, but there are a lot of ways to get events out of C++ and into Java via JNI. 我不确定您想要iOS委托的确切功能,但是有很多方法可以通过JNI将事件从C ++传入Java。 For example: 例如:

  • Pass a "handler" object from Java to C++, and have C++ call its "handleEvent()" method when something happens. 将Java中的“处理程序”对象传递给C ++,并在发生某些情况时让C ++调用其“ handleEvent()”方法。
  • Create a ConcurrentQueue and have a C++ thread put event objects into it while the Java thread blocks waiting for events to happen 创建一个ConcurrentQueue并让一个C ++线程将事件对象放入其中,而Java线程则阻止等待事件发生

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM