[SOLVED] Save into cocos2d::UserDefault from Cocos2dxActivity.java

I want to pass information from a push notification with custom payload into the cocos2dx user defaults.

On iOS i only have to do the following on the AppController.mm:

std::string payload_string([payload UTF8String]);
cocos2d::UserDefault::getInstance()->setStringForKey("notification_payload", payload_string);

and since its cpp code it works just like this.

My question is, how do you do this for the android side?
I get the information like this on the Cococ2dxActivity.java:

String payload = getIntent().getStringExtra("com.tapjoy.PUSH_PAYLOAD");  
if (payload != null) {
    Log.d("Tapjoy", "Tapjoy push notification with payload: " + payload);
    // cocos2d::UserDefault::getInstance()->setStringForKey("notification_payload", payload); // This won't work on java.
}
1 Like

Still haven’t found how to achieve this. Anyone has any ideas?


This might help.

I was looking for other questions similar to mine and i found this:

I think he wanted to achieve the same as i do but they misunderstand him.

The issue is quite simple:

On iOS you can save to the “cocos2d::UserDefault” from the AppController because it can execute cpp code.

But i want to call the same cocos2d function from the “java app controller” (Cococ2dxActivity.java), whats the equivalent for it on java? (that uses the cocos2dxHelper maybe?)

Found the solution: