Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failure delivering result on activity result

Below here sample code intent from camera :

val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    startActivityForResult(intent, REQUEST_CAMERA)

Note: when I press back from camera as result on Activity result show like this:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=65537, result=0, data=null} to activity and Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null:

Try to come out solution like this :

 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { 
           try {
                when(resultCode){
                    Activity.RESULT_CANCELED -> {
                        System.out.println("nothing")
                    }
                    Activity.RESULT_OK -> {
                        if (requestCode == SELECT_FILE)
                            onSelectFromGalleryResult(data)
                        else if (requestCode == REQUEST_CAMERA)
                            onCaptureImageResult(data)
                    }
                }
            }catch (e:NullPointerException){
                e.printStackTrace()
            }
}

still not solve the problem because when i do debuging log it not come out on func onactivityresult if i go press go back from camera and not capture the image. Taking picture and pickup image from gallery work like charm.

Thank you. Please help me to solve this problem since along way solution given not working. It seem like google have to override fun onresultactivity(resultcode!!:Int) <- this one should have return non null.

like image 657
Mohd Hafiz Avatar asked Oct 04 '17 09:10

Mohd Hafiz


People also ask

What does on activity result do?

The android startActivityForResult method, requires a result from the second activity (activity to be invoked). In such case, we need to override the onActivityResult method that is invoked automatically when second activity returns result.

When on activity result is called?

onActivityResult, called after onResume, The basic reason that when your jump from your activity to another activity without calling finish. Then last activity went in onStop state. After onStop, onstart,onResume method call then onActivityResult called.


2 Answers

Shouldn't you override this instead?

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }
like image 153
NSimon Avatar answered Nov 24 '22 08:11

NSimon


I was getting the same issue while implementing the PayPal payment gateway in my app using the kotlin. You just need to add ? with Intent in onActivityResult as the data can be null if data is null or anything goes wrong. So we need to define data as nullable in onActivityResult

Just replace onActivityResult signature of your SomeActivity with below:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
like image 43
AaRiF Avatar answered Nov 24 '22 08:11

AaRiF