Fix IllegalArgumentException when dismissing ProgressDialog in destroyed activity - #254
Draft
cursor[bot] wants to merge 1 commit into
Draft
Conversation
…yed activity Add guard checks before dismissing ProgressDialog to prevent crashes when EmpowerPlantActivity is destroyed while network requests are in flight. Changes: - Added safeDismissProgressDialog() helper method that checks: - Fragment is added (isAdded()) - Activity exists and is not null - Activity is not finishing (!isFinishing()) - Activity is not destroyed (!isDestroyed()) - Dialog is showing before dismissing - Updated all progressDialog.dismiss() calls in OkHttp callbacks to use the safe dismissal method wrapped in runOnUiThread(): - fetchToolsFromServer() onResponse and onFailure callbacks - checkout() onResponse and onFailure callbacks - Removed duplicate progressDialog.dismiss() call in fetchToolsFromServer() This prevents IllegalArgumentException when users navigate away from EmpowerPlantActivity while network requests (fetchToolsFromServer or checkout) are still in progress. Fixes [ANDROID-JM](https://demo.sentry.io/issues/7613949525/)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #254 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 16 16
Lines 883 886 +3
Branches 67 68 +1
=====================================
- Misses 883 886 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
progressDialog.dismiss()was being called in async OkHttp callbacks without checking ifEmpowerPlantActivityis still attached to the window manager, causing crashes when users navigate away before network requests complete.Root Cause
IllegalArgumentExceptionthrown when dismissing a ProgressDialog whose window has been detachedprogressDialog.dismiss()called in OkHttp async callbacks (onResponse/onFailure) on a background thread after the activity may already be destroyedisFinishing/isDestroyed) before dismissingEmpowerPlantActivitywhile a network request (fetchToolsFromServerorcheckout) is in flight, causing the activity to be destroyed before the callback firesSolution
Added
safeDismissProgressDialog()helper method that performs the following checks before dismissing:isAdded())!isFinishing())!isDestroyed())Updated all
progressDialog.dismiss()calls in OkHttp callbacks to use the safe dismissal method wrapped inrunOnUiThread():fetchToolsFromServer()onResponseandonFailurecallbackscheckout()onResponseandonFailurecallbacksAlso removed a duplicate
progressDialog.dismiss()call infetchToolsFromServer().Testing
The fix prevents
IllegalArgumentExceptioncrashes when:EmpowerPlantActivity(loads product list via network request)The dialog will now be safely dismissed only if the activity is still alive and attached.
Fixes ANDROID-JM