java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1888, result=0, data=null} to activity

前端 未结 12 1172
你的背包
你的背包 2020-11-29 01:31

My app allows the user to press a button, it opens the camera, they can take a photo and it will show up in an imageview. If the user presses back or cancel while the camera

相关标签:
12条回答
  • 2020-11-29 02:29
     protected void onActivityResult(int requestCode, int resultCode, Intent data) 
        {  
            if (requestCode == CAMERE_REQUEST && resultCode == RESULT_OK && data != null) 
            {  
               Bitmap photo = (Bitmap) data.getExtras().get("data"); 
               imageView.setImageBitmap(photo);
            } 
    }
    

    You can check if the resultCode equals RESULT_OK this will only be the case if a picture is taken and selected and everything worked. This if clause here should check every condition.

    0 讨论(0)
  • 2020-11-29 02:29

    I faced this problem when I tried to pass a serializable model object. Inside that model, another model was a variable but that wasn't serializable. That's why I face this problem. Make sure all the model inside of an model is serializable.

    0 讨论(0)
  • 2020-11-29 02:30

    I also encountered this question, I solved it through adding two conditions one is:

    resultCode != null
    

    the other is:

    resultCode != RESULT_CANCELED
    
    0 讨论(0)
  • 2020-11-29 02:32

    this is my case

    startActivityForResult(intent, PICK_IMAGE_REQUEST);

    I defined two request code PICK_IMAGE_REQUESTand SCAN_BARCODE_REQUEST with the same value, eg.

    static final int BARCODE_SCAN_REQUEST = 1;

    static final int PICK_IMAGE_REQUEST = 1;

    this could also causes the problem

    0 讨论(0)
  • 2020-11-29 02:36

    I had this error message show up for me because I was using the network on the main thread and new versions of Android have a "strict" policy to prevent that. To get around it just throw whatever network connection call into an AsyncTask.

    Example:

        AsyncTask<CognitoCachingCredentialsProvider, Integer, Void> task = new AsyncTask<CognitoCachingCredentialsProvider, Integer, Void>() {
    
            @Override
            protected Void doInBackground(CognitoCachingCredentialsProvider... params) {
                AWSSessionCredentials creds = credentialsProvider.getCredentials();
                String id = credentialsProvider.getCachedIdentityId();
                credentialsProvider.refresh();
                Log.d("wooohoo", String.format("id=%s, token=%s", id, creds.getSessionToken()));
                return null;
            }
        };
    
        task.execute(credentialsProvider);
    
    0 讨论(0)
  • 2020-11-29 02:36

    My problem was in the called activity when it tries to return to the previous activity by "finishing." I was incorrectly setting the intent. The following code is Kotlin.

    I was doing this:

            intent.putExtra("foo", "bar")
            finish()
    

    When I should have been doing this:

            val result = Intent()
            result.putExtra("foo", "bar")
            setResult(Activity.RESULT_OK, result)
            finish()
    
    0 讨论(0)
提交回复
热议问题