The image is not returned when pic is taken from camera instead app closes and I see home screen of phone when pic is taken and I click on done from camera or click on cross of camera. I noticed onDestroy() method of fragment and fragment’s parent activity gets called as soon as camera is opened. I can see app in background tasks of phone.
android:configChanges="orientation|screenSize" I have tried above in manifest file following 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()
}
Parent activity code
@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();
}