Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:42:27+00:00 2026-06-15T22:42:27+00:00

Once again I have a problem, which I just don’t know how to solve.

  • 0

Once again I have a problem, which I just don’t know how to solve. The problem is how I supposed to pass data back to Android and iOS calling applications from my cocos2d-x app?

For Android, I guess I’ll use activity results when the app ends with JNI, but how can I achieve this on iOS?

Let’s take a not-so-actual example: I have an existing application both on Android and iOS. This application is holding scores for different games, and from this application, you can call other game applications (also written by me). When the called game ends the main application should get the scores back (like an activity result).

If you guys could give me a few pointers, I would really appreciate that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:42:28+00:00Added an answer on June 15, 2026 at 10:42 pm

    In android you can do something like this: (Probably in iOS you can do the same 🙂 )

    For example i would like to return a class with data.
    So i create in
    /cocos2d-2.0-x-2.0.4/cocos2dx/platform/android/java/src/com/example
    (try to put this class in you project i don’t check it)

    package com.example;
    
    public class SimpleClass {
    
        private int a;
        private int b;
    
        public SimpleClass(int a, int b) {
        this.a = a;
        this.b = b;
    
        }
    }
    

    Now in your Cocos2dxActivity you can add native method which will be executed when you exit or other action it’s up to you.

    For example
    private static native SimpleClass nativeReturner();

    and you can execute it in onStop or other method it’s up to you. It will return your SimpleClass

    Next in your project you should have jni/main.cpp a JNI functions so simply you can add like this function:

    jobject Java_org_cocos2dx_lib_Cocos2dxActivity_nativeReturner(JNIEnv* env, jobject obj)
    {
        jint i;
        jobject object;
        jmethodID constructor;
        jclass cls;
        cls = env->FindClass("com/example/SimpleClass");
    
        constructor = env->GetMethodID(cls, "<init>", "(II)V");
                //Here you initialize your class pass here something
        object = env->NewObject(cls, constructor, 5, 12);
        return object;
    } 
    

    This simple function creates you a SimpleClass and initialize it with 5,12 of course you can pass here your object form you cocos game.

    For example in your class that inherits form CCAplication you can store data you would like to pass. Next you can use CCApplication::sharedApplication() or create your own static method.

    Of course in iOS and other platform you must to simlar things.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again I have a problem which I can't find the solution to. A
I have once again fleshed out Ruby, after two years of not touching it,
Once again a question about the garbage collector in actionscript-3: If I have a
This is for edit_inv.php which have some textboxes which users can edit. The problem
I have an application(written in CSharp) which currently connects to just one coherence cluster.
So I am once again dealing with annular sectors which is not my forte.
A have a problem with PHP application, that I'm working on. Main page which
tldr; at bottom. Ok, so once again an interesting problem and I'm looking for
I have a textarea in which I'm putting some default text into. Let's just
I'm looking once again for help from the collective. I created a site which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.