From 0b5f56b682143cf5c0128c5a8410da1be54472b3 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Wed, 25 Nov 2020 08:02:12 +0300 Subject: [PATCH] Fixes theme change issue (#4029) Catch Service Unregistered exception in Activity's onDestroy --- .../contributions/ContributionsFragment.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java index 96efcddb0..7a5465a53 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java @@ -140,6 +140,12 @@ public class ContributionsFragment public void onServiceDisconnected(ComponentName componentName) { // this should never happen Timber.e(new RuntimeException("UploadService died but the rest of the process did not!")); + isUploadServiceConnected = false; + } + + @Override + public void onBindingDied(final ComponentName name) { + isUploadServiceConnected = false; } }; private boolean shouldShowMediaDetailsFragment; @@ -466,17 +472,21 @@ public class ContributionsFragment @Override public void onDestroy() { - compositeDisposable.clear(); - getChildFragmentManager().removeOnBackStackChangedListener(this); - locationManager.unregisterLocationManager(); - locationManager.removeLocationListener(this); - super.onDestroy(); + try{ + compositeDisposable.clear(); + getChildFragmentManager().removeOnBackStackChangedListener(this); + locationManager.unregisterLocationManager(); + locationManager.removeLocationListener(this); + super.onDestroy(); - if (isUploadServiceConnected) { - if (getActivity() != null) { - getActivity().unbindService(uploadServiceConnection); - isUploadServiceConnected = false; + if (isUploadServiceConnected) { + if (getActivity() != null) { + getActivity().unbindService(uploadServiceConnection); + isUploadServiceConnected = false; + } } + } catch (IllegalArgumentException | IllegalStateException exception) { + Timber.e(exception); } } @@ -534,6 +544,7 @@ public class ContributionsFragment @Override public void onDestroyView() { super.onDestroyView(); + isUploadServiceConnected = false; presenter.onDetachView(); }