title: How to show Dialog from a static method
body: <p>In my game, which is done for both Android and IOS using <code>cocos2dx</code>, 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 <code>Cocos2dxActivity</code> 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</p>
  
  <pre><code>void LMJNICommunicator::showVideo()
  {
       LOGD("initialiseDatabase inside LMJNICommunicator");
  
       jmethodID methodID = 0;
       JNIEnv *pEnv = 0;
       pEnv = getJNIEnv();
       jclass ret = pEnv-&gt;FindClass("com/mobinius/lostmonstersclass/LMDatabaseDataManager");
       methodID = pEnv-&gt;GetStaticMethodID(ret, "showVideo", "()V");
  
       if (! methodID)
       {
            LOGD("Failed to find static method id of %s", "showVideo");
            return;
       }
  
       pEnv-&gt;CallStaticVoidMethod(ret,methodID);
       pEnv-&gt;DeleteLocalRef(ret);
  
  }
  </code></pre>
  
  <p>Static method(which is in normal Java class) which I am calling from C++ code</p>
  
  <pre><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
      }
  }
  </code></pre>
  
  <p>I tried to make use of <code>Handler</code> like <a href="https://stackoverflow.com/questions/11483275/how-can-i-send-message-to-handler-from-a-static-function">this</a> but did not get result(got same error in that post).
  Also tried to get a static <code>Context</code> like <a href="https://stackoverflow.com/questions/2002288/static-way-to-get-context-on-android">this</a>.</p>
  
  <p>So, is my way correct? If not correct, please suggest a way how can I implement the same. Thanks.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Finally got answer for this. Earlier I tried running on UI thread with Application static context as in <a href="https://stackoverflow.com/questions/2002288/static-way-to-get-context-on-android">this</a> link but did not get... with Cocos2dxActivity activity instance I got it.</p>
  
  <pre><code>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();            
          }
      });
  
      }
  }
  </code></pre>