ionic-team / ionic-team/capacitor-camera
bug: rotating the device while the photo picker is open relaunches it, stacking a second picker over the preview
- Dominant language
- TypeScript
- Stars
- 4
- Forks
- 1
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 2
Description
### Bug Report
**Plugin version:** `@capacitor/camera` 8.2.0 — also reproduced against `ioncamera-android` 1.0.2 (shipped in 8.2.2)
**Capacitor version:** 8.4.0
**Platform:** Android 13, Samsung Galaxy Tab Active3 (SM-T570), `com.google.android.photopicker` versionName 17
### Current behavior
Rotating the device while the system photo picker is open launches a **second** picker instance on top of the first one. It is most visible when the user has opened the picker's preview screen: after rotating, the selection grid reappears over the preview.
### Expected behavior
A configuration change should not relaunch the picker. The already-open picker should simply handle the rotation itself.
### Steps to reproduce
1. Call `Camera.chooseFromGallery({ allowMultipleSelection: true })`.
2. In the system photo picker, select a photo and open the preview.
3. Rotate the device to landscape.
4. A second picker opens on top.
The picker options are irrelevant — the same happens with default options and with `allowMultipleSelection: false`.
### Root cause
`IONCAMROpenPhotoPickerActivity` is declared in the library manifest **without `android:configChanges`**:
```xml
```
So a rotation destroys and recreates it. Its `onCreate` then passes `savedInstanceState` to `super` and never reads it again, calling `launchSinglePicker` / `launchMultiplePicker` unconditionally:
```
protected void onCreate(android.os.Bundle);
0: aload_0
1: aload_1
2: invokespecial // ComponentActivity.onCreate
... // reads intent extras only — savedInstanceState is never tested
110: invokespecial // launchMultiplePicker
119: invokespecial // launchSinglePicker
```
Every recreation therefore launches another picker. This is visible in the activity stack, captured while the bug was on screen:
```
#3 com.google.android.photopicker/MainActivity <- resumed, the one "on top"
#2 com.google.android.photopicker/MainActivity <- first instance, showing the preview
#1 /io.ionic.libs.ioncameralib.view.IONCAMROpenPhotoPickerActivity
#0 /MainActivity
```
Both picker instances have `resultTo=IONCAMROpenPhotoPickerActivity`.
Note that the host app's own `MainActivity` declares `android:configChanges="orientation|screenSize|…"` (the Capacitor default), which is why the rest of the app absorbs rotation without issue — the library's proxy activity does not inherit that.
### Suggested fix
Either guard the launch in `onCreate`:
```kotlin
if (savedInstanceState == null) {
// launchSinglePicker / launchMultiplePicker
}
```
or declare `android:configChanges` on the activity in the library manifest.
`IONCAMRImageEditorActivity` and `IONCAMRLoadingActivity` are declared the same way and may be affected by the same pattern.
### Workaround
Overriding the declaration in the app manifest stops the relaunch:
```xml
```
Contributor guide
Research direction
Locate IONCAMROpenPhotoPickerActivity and its library manifest declaration, then inspect how onCreate uses savedInstanceState before launching the picker. Reproduce the rotation flow on Android with the photo picker open. Done means rotation preserves the existing picker without stacking another instance; check whether the similarly declared image editor and loading activities show the same pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, typescript
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100