Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I send cpp callback function pointer to java
    primarykey
    data
    text
    <p>I am working on android application which is written in cpp (cocos2dx) Now I'm doing a facebook module which has to be implemented in java.</p> <p>The facebook calls are asynchronic so I cannot know when the action is completed unless I'll have a callback from the java part to the cpp.</p> <p>For example:</p> <p>The JNI part should look like something like that:</p> <pre><code>void CCAndroidApplication::login2Facebook() { JniMethodInfo minfo; if(JniHelper::getStaticMethodInfo(minfo, "org/cocos2dx/example/myandroidtest", "login2Facebook", "(**POINTER TO CALLBACK METHOD DidLogin()**)V")) { minfo.env-&gt;CallStaticVoidMethod(minfo.classID, minfo.methodID); minfo.env-&gt;DeleteLocalRef(minfo.classID); } } </code></pre> <p>and the java part should look like:</p> <pre><code>public static void login2Facebook(**POINTER TO native CALLBACK METHOD DidLogin()**) Session.openActiveSession(me, true, new Session.StatusCallback() { @Override public void call(Session session, SessionState state, Exception exception) { mSession = session; if (session.isOpened()) { Request.executeMeRequestAsync(session, new Request.GraphUserCallback() { @Override public void onCompleted(GraphUser user, Response response) { if (user != null) { **Call nativeDidLogin()**; } } }); } } }); } </code></pre> <p>It is also fine if I can send cpp object that contains the method like</p> <pre><code>class delgateMethods { public: void didLogin(); } </code></pre> <p>and call it from the java.</p> <p>My question is: Is it possible to send a pointer to function over the JNI and call it in the java part?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload