Skip to content

Conversation

@Suryansh0910
Copy link

Fixes #8246

Description

When the Android system destroys and recreates the Activity while a file picker is open (due to backgrounding or memory pressure), the ValueCallback reference is lost, causing file uploads to fail silently.

This fix stores the file chooser callbacks in static variables so they survive activity recreation. When the activity result is received:

  • If the instance callback exists, it's used normally
  • If the instance callback is null, the static pending callback is used

Changes

  • Added static variables to store pending file path callback, image URI, and file chooser type
  • Added FileChooserType enum to track which picker was opened
  • Added handlePendingFileChooserResult() to handle results when activity was recreated
  • Added clearPendingFileChooserState() to clean up static state
  • Updated showImageCapturePicker(), showVideoCapturePicker(), and showFilePicker() to store callbacks before launching

Fixes ionic-team#8246

When the Android system destroys and recreates the Activity while a file
picker is open (due to backgrounding or memory pressure), the ValueCallback
reference is lost, causing file uploads to fail silently.

This fix stores the file chooser callbacks in static variables so they
survive activity recreation. When the activity result is received:
- If the instance callback exists, it's used normally
- If the instance callback is null, the static pending callback is used

Changes:
- Added static variables to store pending file path callback, image URI,
  and file chooser type
- Added FileChooserType enum to track which picker was opened
- Added handlePendingFileChooserResult() to handle results when activity
  was recreated
- Added clearPendingFileChooserState() to clean up static state
- Updated showImageCapturePicker(), showVideoCapturePicker(), and
  showFilePicker() to store callbacks before launching
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 5, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 6, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 7, 2025
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.

Image upload failed

1 participant