android - onActivityResult is not called (Kotlin) -


i need help. on oncreate() have code:

    takephotodialog = dialoggetphotofrom.getinstance().apply {         setlistener(object : dialoggetphotofrom.dialoglistener {             override fun ontakefromgallery() {                 log.v("projectdetails", "ontakefromgallery called")                 val intent = intent().apply {                     type = "image/*"                     action = intent.action_get_content                 }                 startactivityforresult(intent.createchooser(intent, "select image"), request_pick_image)             }              override fun ontakephoto() {                 dispatchtakepictureintent()             }         })     }      projectdetails_pickimage.setonclicklistener { takephotodialog?.show(supportfragmentmanager) } 

an on onactivityresult, wrote:

override fun onactivityresult(requestcode: int, resultcode: int, data: intent?) {     super.onactivityresult(requestcode, resultcode, data)     when (requestcode) {         request_pick_image -> {             log.v("projectdetails", "request_pick_image called")             if (resultcode == activity.result_ok) {                 if (data != null) {                     try {                         val inputstream = contentresolver.openinputstream(data.data)                         val bitmap = bitmapfactory.decodestream(inputstream)                         projectdetails_image.setimagebitmap(bitmap)                         // todo save image uri database                     } catch (e: exception) {                         toast.maketext(this, "can't set background.", toast.length_short).show()                     }                 } else {                     log.v("projectdetails", "data null")                 }             }         }     } } 

the problem is, onactivityresult() doesn't fire when image selected. should do?

solved it! solution put codes inside ontakegallery() function function belongs activity class. code this:

takephotodialog = dialoggetphotofrom.getinstance().apply {     setlistener(object : dialoggetphotofrom.dialoglistener {         override fun ontakefromgallery() {             dispatchselectfromgalleryintent()         }          override fun ontakephoto() {             dispatchtakepictureintent()         }     }) }  projectdetails_pickimage.setonclicklistener {      takephotodialog?.show(supportfragmentmanager) } 

and extracted codes goes here:

private fun dispatchselectfromgalleryintent() {     val intent = intent().apply {         type = "image/*"         action = intent.action_get_content     }     startactivityforresult(intent.createchooser(intent, "select image"), request_pick_image) } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -