Skip to content

Fix IllegalArgumentException when dismissing ProgressDialog in destroyed activity - #254

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
illegalargumentexception-viewdecorview9af2f92empowerplantactivity-not-2elhm2
Draft

Fix IllegalArgumentException when dismissing ProgressDialog in destroyed activity#254
cursor[bot] wants to merge 1 commit into
mainfrom
illegalargumentexception-viewdecorview9af2f92empowerplantactivity-not-2elhm2

Conversation

@cursor

@cursor cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown

Problem

progressDialog.dismiss() was being called in async OkHttp callbacks without checking if EmpowerPlantActivity is still attached to the window manager, causing crashes when users navigate away before network requests complete.

Root Cause

  1. IllegalArgumentException thrown when dismissing a ProgressDialog whose window has been detached
  2. progressDialog.dismiss() called in OkHttp async callbacks (onResponse/onFailure) on a background thread after the activity may already be destroyed
  3. No guard checks whether the hosting Activity is still alive (isFinishing/isDestroyed) before dismissing
  4. User navigates away from EmpowerPlantActivity while a network request (fetchToolsFromServer or checkout) is in flight, causing the activity to be destroyed before the callback fires

Solution

Added safeDismissProgressDialog() helper method that performs the following checks before dismissing:

  • Fragment is added to activity (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

Also removed a duplicate progressDialog.dismiss() call in fetchToolsFromServer().

Testing

The fix prevents IllegalArgumentException crashes when:

  1. User opens EmpowerPlantActivity (loads product list via network request)
  2. Immediately navigates back before the network request completes
  3. The OkHttp callback fires and attempts to dismiss the progress dialog

The dialog will now be safely dismissed only if the activity is still alive and attached.

Fixes ANDROID-JM

Open in Web Open in Cursor 

…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/)
@sentry

sentry Bot commented Aug 9, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (2bef372) to head (0c7bc3a).

Files with missing lines Patch % Lines
.../example/vu/android/empowerplant/MainFragment.java 0.00% 9 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant