OnActivityResult未在活动的片段中调用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OnActivityResult未在活动的片段中调用相关的知识,希望对你有一定的参考价值。
我的活动流程是这样的。
在Fragment
A中,它允许用户捕获图像,图像将显示在Activity B
上,供用户进行一些编辑。
片段A.
mImageListAdapter.mAddImageClickListener = object : ImageListAdapter.AddImageClickListener {
override fun addImageClicked() {
val options = arrayOf<CharSequence>("Take Photo", "Choose From Gallery", "Cancel")
val builder = android.support.v7.app.AlertDialog.Builder(activity)
builder.setTitle("Select Option")
builder.setItems(options) { dialog, item ->
if (options[item] == "Take Photo") {
dialog.dismiss()
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(intent, CAMERA_CAPTURE)
}
}
builder.show()
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
var bitmap: Bitmap? = null
if (requestCode == CAMERA_CAPTURE && resultCode == Activity.RESULT_OK) {
val extras = data?.extras
if (extras != null) {
bitmap = extras.get("data") as Bitmap
val intent = Intent(activity, ActivityB::class.java)
intent.putExtra("bitmap", bitmap)
startActivityForResult(intent, 12)
}
} else if (requestCode == 12 && resultCode == Activity.RESULT_OK) {
longToast("It get result from Activity B")
} else {
longToast("Nothing")
}
}
在活动B中,单击完成按钮后,编辑后的图像将返回到片段A,我将在此处显示“It get result from Activity B
”,但不会显示任何内容!
活动B.
doneBtn.setOnClickListener {
image.buildDrawingCache()
val bitmap = image.getDrawingCache()
val resultIntent = Intent()
resultIntent.putExtra("bitmap", bitmap)
setResult(Activity.RESULT_OK, resultIntent)
finish()
}
以上是关于OnActivityResult未在活动的片段中调用的主要内容,如果未能解决你的问题,请参考以下文章
onActivityResult 未在 Android API 23 的片段上调用
Zxing QR扫描仪onActivityResult未在片段中调用[重复]