Skip to content

fix(android): preserve file chooser callback across activity recreation#8275

Open
Suryansh0910 wants to merge 1 commit intoionic-team:mainfrom
Suryansh0910:fix/file-upload-after-background-8246
Open

fix(android): preserve file chooser callback across activity recreation#8275
Suryansh0910 wants to merge 1 commit intoionic-team:mainfrom
Suryansh0910:fix/file-upload-after-background-8246

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
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 8, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 9, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 10, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 11, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 12, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 13, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 14, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 15, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 16, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 17, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 18, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 19, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 20, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 21, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 22, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 23, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 24, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 25, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 26, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 27, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 28, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 29, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 30, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Dec 31, 2025
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 1, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 2, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 30, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Jan 31, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 1, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 2, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 3, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 4, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 5, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 6, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 7, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 8, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 9, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 10, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 11, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 12, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 13, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 14, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 15, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 16, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 17, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 18, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 19, 2026
@OS-pedrogustavobilro
Copy link
Contributor

Hey @Suryansh0910, @zgl612, are you able to share a sample application (GitHub repo) with which you reproduced the issue + tested these fixes?. I think it will be tougher to get this merged without it.

Thanks!

riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 20, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 21, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 22, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 23, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 24, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 25, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 26, 2026
riderx pushed a commit to Cap-go/capacitor-plus that referenced this pull request Feb 27, 2026
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

2 participants