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 8832485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:32:30+00:00 2026-06-14T08:32:30+00:00

In my game, which is done for both Android and IOS using cocos2dx ,

  • 0

In my game, which is done for both Android and IOS using cocos2dx, I have to show video(for Android). I am planning to show it in Dialog(on top of game view). Problem is that, I don’t have any Activity referenced to show Dialog(as Dialogs can only be shown in Activities). Even though, In cocos2dx lib folder, there is a Cocos2dxActivity but I am not getting how to make use of it. From C++ code, I am calling a static method from Java class as below

void LMJNICommunicator::showVideo()
{
     LOGD("initialiseDatabase inside LMJNICommunicator");

     jmethodID methodID = 0;
     JNIEnv *pEnv = 0;
     pEnv = getJNIEnv();
     jclass ret = pEnv->FindClass("com/mobinius/lostmonstersclass/LMDatabaseDataManager");
     methodID = pEnv->GetStaticMethodID(ret, "showVideo", "()V");

     if (! methodID)
     {
          LOGD("Failed to find static method id of %s", "showVideo");
          return;
     }

     pEnv->CallStaticVoidMethod(ret,methodID);
     pEnv->DeleteLocalRef(ret);

}

Static method(which is in normal Java class) which I am calling from C++ code

Class LMDatabaseDataManager {

    public static void showVideo() {

         Dialog dialog = new Dialog(Cocos2dxActivity.getInstance());
         dialog.show();
        // getting Can't create handler inside thread that has not called Looper.prepare() error
    }
}

I tried to make use of Handler like this but did not get result(got same error in that post).
Also tried to get a static Context like this.

So, is my way correct? If not correct, please suggest a way how can I implement the same. Thanks.

Edit:

Finally got answer for this. Earlier I tried running on UI thread with Application static context as in this link but did not get… with Cocos2dxActivity activity instance I got it.

Class LMDatabaseDataManager {

    public static void showVideo() {        

    Cocos2dxActivity.getInstance().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            Dialog dialog = new Dialog(Cocos2dxActivity.getInstance());
            dialog.show();            
        }
    });

    }
}
  • 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-14T08:32:31+00:00Added an answer on June 14, 2026 at 8:32 am

    Try adding the appropriate lines in Cocos2dxActivity:

    public class Cocos2dxActivity extends Activity {
        private static Cocos2dxActivity instance = null;
       @Override public void onCreate(Bundle b) {
         ...
         this.instance = this;
         }
    
         public static Cocos2dxActivity getInstance() {
            return instance;
         }
    
    
    
    }
    

    When you want to create your dialog:

    if (Cocos2dxActivity.getInstance() != null)  {
        AlertDialog dialog = new AlertDialog(Cocos2dxActivity.getInstance());
        // rest of your dialog code goes here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an android game which loads a list of 'games' the user has
I am writing a game which uses opengles. I have created my renderer class
I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I'm writing a game which uses a border layout with a JPanel using BorderLayout.CENTER.
I have an animated game which is generally achieving 25-30 frames per second, though
I have an iPhone game which I am porting to PC. The game uses
I'm using AndroidBillingLibrary to implement in-app purchases for my game. I've done the following:
I am developing a game in which I have some game play screens, game
I am making a game for Android, in which two devices connect and then
I am building an android game which is intended to be a multiplayer game.

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.