从照相机拍摄照片时,应用程序关闭,并且当我拍摄照相机并单击“完成”或单击照相机十字时,应用程序关闭并且我看到手机的主屏幕时,图像不会返回。我注意到片段的onDestroy()方法和片段的父活动在打开相机后立即被调用。我可以在手机的后台任务中看到应用程序。
android:configChanges =“ orientation | screenSize” 我已经在Android: Activity getting Destroyed after calling Camera Intent
之后的清单文件中进行了尝试override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setUpPermissions()
}
private fun setUpPermissions() {
if (!hasPermissions(activity, *PERMISSIONS)) {
ActivityCompat.requestPermissions(activity!!, PERMISSIONS, PERMISSION_ALL)
} else {
showDialogForCameraAndGallery()
}
}
private fun showDialogForCameraAndGallery() {
val builder = android.support.v7.app.AlertDialog.Builder(activity!!)
builder.setTitle("Select Option")
builder.setItems(options, DialogInterface.OnClickListener { dialog, item ->
if (options[item] == "Take Photo") {
dialog.dismiss()
openCamera()
} else if (options[item] == "Choose From Gallery") {
dialog.dismiss()
openGallery()
} else if (options[item] == "Cancel") {
dialog.dismiss()
}
})
builder.show()
}
private fun openCamera() {
val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(intent,
CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Log.e(" on Activity called", " frgamnet$requestCode")
}
override fun onDestroy() {
Log.e(" ondestroy ", "of fragment");
super.onDestroy()
}
父母活动代码
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e( " onActivity result ", "called");
}
@Override
public void onDestroy() {
Log.e(" desturo called", "activity");
super.onDestroy();
}