From 1167837b9f049896739eea805cba94420d77dac7 Mon Sep 17 00:00:00 2001 From: misaochan Date: Thu, 25 Jan 2018 03:35:12 +1000 Subject: [PATCH] Check that fragment is added to activity to prevent crash --- .../nrw/commons/contributions/ContributionController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java index 0bd78c874..86d8e79ed 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java @@ -70,6 +70,9 @@ public class ContributionController { requestWritePermission(fragment.getContext(), takePictureIntent, lastGeneratedCaptureUri); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureUri); + if (!fragment.isAdded()) { + return; + } fragment.startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA); } @@ -79,6 +82,9 @@ public class ContributionController { pickImageIntent.setType("image/*"); Timber.d("startGalleryPick() called with pickImageIntent"); //TODO Add fix for IllegalStateException here + if (!fragment.isAdded()) { + return; + } fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY); }