Outdated Docs > EasyNDK > How to work on Android - C++Java

How to work on iOS - C*+ and Java
h2. Purpose.
On a button click from Cocos2dx Scene, i have to send a message to Java popup on native platform. Lets find how to achieve it.
h2. Includes
You need to make several includes to your project, i have created an online repo that has been divided with respect to category
of environments. Please make sure you include all the files for C*+ and Java. Here is the link to the online repo :


From C*+

<pre><code class="cpp">
#include “NDKHelper.h”
// The button click method of Cocos2dx
void HelloWorld::menuCloseCallback
// Register a selector in a global space
// So that when our native environment will call the method with the string
// It can respond to the selector
// Note : Group name is there for ease of removing the selectors
// Making parameters for message to be passed to native language
// For the ease of use, i am sending the method to be called name from C*+
CCDictionary* prms = CCDictionary::create();
prms->setObject(CCString::create(“SampleSelector”), “to_be_called”);

// Finally call the native method in current environment
SendMessageWithParams(string(“SampleSelector”), prms);

// A selector that will respond to us, when native language will call it
void HelloWorld::SampleSelector(CCNode sender, voiddata)
CCLog(“Called from native environment”);

// Destructor to remove all the selectors which are grouped as HelloWorldSelectors
// Remove the associated selector group from the global space,
// Because we are destroying this instance


From Java

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)

    // In the main Activity, assigning that activity as a receiver for C++ messages

// Implement the method to be called for a message from C++
// Be sure to name the method to be of the same string as you will pass from C++
// Like we passed "SampleSelector" from C++, that is why created this method
public void SampleSelector(JSONObject prms)
    Log.v("SampleSelector", "purchase something called");
    Log.v("SampleSelector", "Passed params are : " + prms.toString());

    String CPPFunctionToBeCalled = null;
        CPPFunctionToBeCalled = prms.getString("to_be_called");
    catch (JSONException e)
        // TODO Auto-generated catch block

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("This is a sample popup on Android").
    setTitle("Hello World!").
    setNeutralButton("OK", null).show();

    // Send C++ a message with paramerts
    // C++ will recieve this message, only if the selector list will have a method
    // with the string we are passing
    AndroidNDKHelper.SendMessageWithParameters(CPPFunctionToBeCalled, null);


For connecting others SDK’s you can simply follow Java guides of those SDKs and respectively implement the message passing mechanism to call
them from Cocos2dx, be it any of the SDK. I have implemented AppCircle, Flurry and many other SDKs using this method.

A sample project with complete source is available online, here is the link :
Sample Android Project

Enjoy programming :)

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.