capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

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

Open Suryansh0910 opened this issue 1 year ago • 1 comments

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

Suryansh0910 avatar Dec 04 '25 18:12 Suryansh0910

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!

OS-pedrogustavobilro avatar Feb 19 '26 12:02 OS-pedrogustavobilro