Failure delivering result on activity result
Asked Answered
V

2

13

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.

Vincentvincenta answered 4/10, 2017 at 9:36 Comment(3)
Check this: github.com/firebase/FirebaseUI-Android/issues/…Arlo
public void onActivityResult(int requestCode, int resultCode, Intent data) this one i derive from parent fragment. so how to do it in kotlin?Vincentvincenta
Java to Kotlin converter incorrectly put data: Intent as the param, but it should be nullable, so change it to data: Intent?.Dulcle
I
27

Shouldn't you override this instead?

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }
Imperishable answered 4/10, 2017 at 10:15 Comment(2)
In extend fragment no need to put super like this override fun onActivityResult(){ // no need super} and if I put also same got crash. It seems that there is bugs in latest android build 26.0.2Vincentvincenta
the issue is as a result of using ...data: Intent.. instead of ...data: Intent?.. in onActivityResult parameters.Person
S
19

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?)
Shreveport answered 30/10, 2017 at 11:28 Comment(2)
yup. New converter kotlin got problem.Vincentvincenta
This totally helped me! Thank you!Marola

© 2022 - 2024 — McMap. All rights reserved.