Asus Tablet 3.2 with Gallery

hi,

I am developing an application in cocos2d-x that needs the gallery. In version 2.1, the application works perfectly but if running in version Android 3.2 (honeycomb), when selecting a photo of gallery for the second time, throws me this error:

FATAL EXCEPTION: main
E/AndroidRuntime(23714): java.lang.RuntimeException: Unable to resume activity 
{com.company.application/com.company.application.class}: java.lang.IllegalStateException: 
trying to requery an already closed cursor  android.content.ContentResolver$CursorWrapperInner@4081bfd0
E/AndroidRuntime(23714):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2288)
E/AndroidRuntime(23714):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2316)
E/AndroidRuntime(23714):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1050)
E/AndroidRuntime(23714):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(23714):    at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime(23714):    at android.app.ActivityThread.main(ActivityThread.java:4123)
E/AndroidRuntime(23714):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(23714):    at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(23714):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
E/AndroidRuntime(23714):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
E/AndroidRuntime(23714):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(23714): Caused by: java.lang.IllegalStateException: 
trying to requery an already closed cursor  android.content.ContentResolver$CursorWrapperInner@4081bfd0
E/AndroidRuntime(23714):    at android.app.Activity.performRestart(Activity.java:4438)
E/AndroidRuntime(23714):    at android.app.Activity.performResume(Activity.java:4460)
E/AndroidRuntime(23714):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2278)

i’m not yet tested in version 4.01 (Android) in debug mode, but it happens exactly the same thing, the application crash. What I see is that just open the gallery and select a picture, for the second time, that the problem happens even if the method “onActivityResult” do nothing inside.

From what I see in the report, the application is trying to access a cursor that is already closed.

Someone can help me with this problem?

Hello,
can you add code sample, how to access photo galery?

Thanks

MG

Ok,

I’m using the JNI method to invoke Java method. This java method call a Handler object and this handler onject invoke the gallery. Now, is the code:

in cocos2d-x:

        JNIEnv *env;
    JniHelper::getJavaVM()->GetEnv((void**)&env, JNI_VERSION_1_4); 
    jclass handlerClass = JniHelper::getClassID("com/company/application/class");
    if(handlerClass==NULL) {
        return;
    }
    jmethodID mid = env->GetMethodID(handlerClass, "openGalley", "()V");
    if (mid == NULL) {
        return;
    }
    env->CallVoidMethod(handlerClass, mid);

openGallery Method on java:

private void openGalley() {                      
      galleryHandler.sendEmptyMessage(0);
}   

the gallery Handler:

...
public void handleMessage(Message msg) {   
     super.handleMessage(msg);     
     Thread aux = new Thread(new Runnable() {
          Intent intent = new Intent();

          @Override  
          public void run() {
               intent.setType("image/*");
               intent.setAction(Intent.ACTION_PICK);
               Controller.getInstance().getActivity().startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);    
          }
     });              
     aux.start();                                                                                     
}    
...

So, this is a code that use from open gallery. The callback method when i selecting the photo is:

     public void onActivityResult(int requestCode, int resultCode, final Intent data) {

        if(requestCode==SELECT_PICTURE) {
            GalleryOpened = 0;               
        }                                                   


        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE && data != null && data.getData() != null) {
                /* something logic code */
                return;
            }
        }
     }

I use anything wrong?