传递结果失败ResultInfo {who = null,request = 200,result = -1,data = Intent

时间:2012-03-10 19:09:20

标签: android android-activity

我想从主要活动中调用我的孩子活动。在此期间,我需要将linkedhashSet传递给它。 在子活动中,我想对这个hashset执行一些操作, 并且在单击子活动中对话框的“确定”按钮时,我想将此新的linkedhashset返回给pareent。

目前我在发送原始hashset时在父活动中使用以下代码:

Bundle bundle = new Bundle();
                bundle.putSerializable("keyThumbNails", thumbNailsLnkdhs);

                Intent AndroidCustomGalleryActivityIntent = new Intent(parentActivity.this, childActivity.class);
                childActivity.putExtras(bundle);
                startActivityForResult(childActivity,200);



Log.d(LOGGER, "ChildyActivityIntent called ");

工作正常。 我能够在子活动中收到这个hashset,我可以对它进行操作。

我正在尝试使用以下代码发送新的hashset:

 new AlertDialog.Builder(this)
          .setMessage(mymessage)
          .setTitle(title)

          .setNeutralButton(android.R.string.ok,
             new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton){
                 Log.d(LOGGER, "AlertDialog neutral btn");
//                 // the button was clicked
                    Bundle bundleToSend = new Bundle();
                    bundleToSend.putSerializable("keyThumbNailsOfSelectedImages", SelectedThumbnailsPathsLnkdhs);

                    Intent SearchWebForWallPaperActivityIntent = new Intent(AndroidCustomGalleryActivity.this, SearchWebForWallPaperActivity.class);
                    SearchWebForWallPaperActivityIntent.putExtra("RESULT",bundleToSend);
                    setResult(Activity.RESULT_OK, SearchWebForWallPaperActivityIntent);
                    finish();
             }
             })
          .show();
       }

这是正确的。

在父活动中我使用以下代码来接收此hashset ...此代码在记录“got bundle”后出现问题...

@Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) {     
      super.onActivityResult(requestCode, resultCode, data); 
      switch(requestCode) { 
        case (200) : { 
          if (resultCode == Activity.RESULT_OK) { 
              Log.d(LOGGER, "inside RESULT OK");
              //Bundle revievedBundle = this.getIntent().getExtras();
              Bundle recievedBundle = data.getExtras();
              Log.d(LOGGER, "got bundle");
             // if(recievedBundle.isEmpty()){
                  //Log.d(LOGGER, "its empty");
              //}
              SelectedThumbnailsPathsLnkdhs = (LinkedHashSet<String>) recievedBundle.getSerializable("keyThumbNailsOfSelectedImages");
            Log.d(LOGGER, "ThumbNailsLnkdhs size in SearchWebForWallPaperActivity intent: "+SelectedThumbnailsPathsLnkdhs.size());

             Toast.makeText(getApplicationContext(),
                       "ThumbNailsLnkdhs size in old intent: "+SelectedThumbnailsPathsLnkdhs.size(), Toast.LENGTH_LONG).show();

          } 
          break; 
        } 
      } 
    }

我尝试了很多东西,搜索很长时间以使其正常工作。 但无法成功:( 谁能看看这个代码并帮助我?

以下是logcat跟踪:

03-11 00:24:20.310: D/ADITYA(3959): inside RESULT OK
03-11 00:24:20.310: D/ADITYA(3959): got bundle
03-11 00:24:20.341: D/AndroidRuntime(3959): Shutting down VM
03-11 00:24:20.341: W/dalvikvm(3959): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
03-11 00:24:20.420: E/AndroidRuntime(3959): FATAL EXCEPTION: main
03-11 00:24:20.420: E/AndroidRuntime(3959): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=200, result=1, data=Intent { cmp=com.practice.wallpaper/.SearchWebForWallPaperActivity (has extras) }} to activity {com.practice.wallpaper/com.practice.wallpaper.SearchWebForWallPaperActivity}: java.lang.NullPointerException
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread.access$2800(ActivityThread.java:125)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.os.Looper.loop(Looper.java:123)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at java.lang.reflect.Method.invokeNative(Native Method)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at java.lang.reflect.Method.invoke(Method.java:521)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at dalvik.system.NativeStart.main(Native Method)
03-11 00:24:20.420: E/AndroidRuntime(3959): Caused by: java.lang.NullPointerException
03-11 00:24:20.420: E/AndroidRuntime(3959):     at com.practice.wallpaper.SearchWebForWallPaperActivity.onActivityResult(myActivity.java:198)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.Activity.dispatchActivityResult(Activity.java:3890)
03-11 00:24:20.420: E/AndroidRuntime(3959):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
03-11 00:24:20.420: E/AndroidRuntime(3959):     ... 11 more

1 个答案:

答案 0 :(得分:0)

解决方案:

在SurfaceChanged中绘制位图,使用标记是否加载图像。

显然,在MediaStore活动返回选择之后,SurfaceView尚未准备就绪,

自: https://stackoverflow.com/a/4891558/4339857