react-native-image-picker
react-native-image-picker copied to clipboard
The app get restared when I press confirm button afer I take a photo with the camera [🐛]
Description
I'm having an issue with react-native-image-picker library. Taking a photo from gallery is working perfectly. My problem is with the camera. Once that I take a photo and press on the confirm button to get the asset information, the app get restared.
I don't have errors on console and also I have the permissions. The app just get restared with no reasons.
How to repeat issue and example
- step to reproduce the issue
- Open camera
- Take a photo
- Press confirm button
Additional Information
- Image Picker version: "^4.7.3"
- React Native version: "0.68.1"
- Platform: Android
- Development Operating System: MacOS
Many bugs will pops up for using react-native: 0.68+ because RN architecture has changed so maintainers has to update their repos and fix the bugs if package contains bridges
Getting this issue too - if a fix can be issued sooner rather than later that would be great!
(Considering the entire library is useless without this functionality)
Many bugs will pops up for using react-native: 0.68+ because RN architecture has changed so maintainers has to update their repos and fix the bugs if package contains bridges
Does it mean downgrading RN to 0.67 is a possible solution
@josephgodwinkimani Yes. My app is running RN 0.67 and image-picker works fine
i upgraded to React Native 0.68.x and im getting crash when take a phone from camera
I got similar issue, but happens only with camera and only on android with low RAM. Looks like when this library opens system camera, android decides to kill origin app as wants to utilize RAM. Earlier such issues happen with me even on native android. Solution for android can be to implement camera UI in scope of this library and run this UI in same android process to avoid RAM utilization.
implement camera UI in scope of thi
I got similar issue, but happens only with camera and only on android with low RAM. Looks like when this library opens system camera, android decides to kill origin app as wants to utilize RAM. Earlier such issues happen with me even on native android. Solution for android can be to implement camera UI in scope of this library and run this UI in same android process to avoid RAM utilization.
Kindly give an example as to how this can be achieved
implement camera UI in scope of thi
I got similar issue, but happens only with camera and only on android with low RAM. Looks like when this library opens system camera, android decides to kill origin app as wants to utilize RAM. Earlier such issues happen with me even on native android. Solution for android can be to implement camera UI in scope of this library and run this UI in same android process to avoid RAM utilization.
Kindly give an example as to how this can be achieved
I decided to migrate camera functionality from this library to react-native-camera-kit . This will require more effort to implement some UI on your side. And that's not all. If you used custom image width/height your'll need this library for image resizing of just captured photos - react-native-image-resizer .
i hope this issue get fixed by the maintainers in the next release
It looks as it's not really a library problem. When you launch the camera, it launches as new Activity
a from Android P (9) and on, it's allowed the OS to kill background activities. That's why it don't give an error message.
There is a website about it: https://dontkillmyapp.com/
Just posted two solutions here: https://stackoverflow.com/questions/68206801/expo-image-picker-crashes-app-after-using-launchcameraasync-on-android/74816435#74816435
I have same problem with smartphone from company Xiaomi. After restarting my smartphone, then the bug dissapeared.
I have the same issue with React Native 0.59
, but it is very intermittent and I can't reproduce this issue.
Sometimes it happens and sometimes nothing happened:)
I got similar issue, but happens only with camera and only on android with low RAM. Looks like when this library opens system camera, android decides to kill origin app as wants to utilize RAM. Earlier such issues happen with me even on native android. Solution for android can be to implement camera UI in scope of this library and run this UI in same android process to avoid RAM utilization.
I have the same issue with React Native
0.59
, but it is very intermittent and I can't reproduce this issue. Sometimes it happens and sometimes nothing happened:)I got similar issue, but happens only with camera and only on android with low RAM. Looks like when this library opens system camera, android decides to kill origin app as wants to utilize RAM. Earlier such issues happen with me even on native android. Solution for android can be to implement camera UI in scope of this library and run this UI in same android process to avoid RAM utilization.
The package expo-image-picker is similar to this one. It states on docs: https://docs.expo.dev/versions/latest/sdk/imagepicker/#imagepickergetpendingresultasync
Android system sometimes kills the MainActivity after the ImagePicker finishes. When this happens, we lost the data selected from the ImagePicker. However, you can retrieve the lost data by calling getPendingResultAsync. You can test this functionality by turning on Don't keep activities in the developer options.
To reproduce the crash. Do the following:
- Open your app
- Open the camera
- Turn on 'Don't keep activities'.
- Finish working with the camera.
Sometimes turning dont keep activities on before, don permit camera to open.
I've listed some workarounds on stackoverflow: https://stackoverflow.com/questions/68206801/expo-image-picker-crashes-app-after-using-launchcameraasync-on-android/74816435#74816435
Be prepared to crash. Save all states and navigation stack on local-storage, launchCamera. The app will restart, you will restore all the screen/navigation/data/etc, and get photo using the ImagePicker.getPendingResultAsync.
Is there an equivalent of ImagePicker.getPendingResultAsync in this package?
Anyone facing this app kill issue, a workaround is the notifee foreground service. By using that, it will keep your app alive.
What you must do:
- Register your foreground service with notifee
- Display an ongoing notification with notifee
- When returning or unmounting ~cancel the notification and~ stop the foreground service
Note: See also this issue where I'm asking to documented better the limitations and explained better the solution
Anyone facing this app kill issue, a workaround is the notifee foreground service. By using that, it will keep your app alive.
What you must do:
1. Disaply an ongoing notification with notifee 2. Register your foreground service with notifee 3. When returning or unmounting cancel the notification and stop the foreground service
Looks very promissing!!!! I'll test your solution next week!
The Expo says that is possible to simulate the crash situation using the Android Developer option don't keep activities
as stated on (expo docs)[https://docs.expo.dev/versions/v47.0.0/sdk/imagepicker/#imagepickergetpendingresultasync]
How to test:
- Open your camera. (The notifee will pop up also)
- Open android developer options and turn on the
don't keep activities
option (or just do a toggle), this option forces the android to kill all background activities. It works exactly the same way as the distributors "garbage collector". - Take a picture and check if the other activity is killed or not.
Also, for some reason the activity kill is not happening anymore. I use most samsung devices new and old, and both of them had performance and security updated
.
Before, when i did a stress test of opening and closing the camera several times. After ~1min it would crash the app at least once.
But this is not happening anymore.
Anyone facing this app kill issue, a workaround is the notifee foreground service. By using that, it will keep your app alive.
What you must do:
- Display an ongoing notification with notifee
- Register your foreground service with notifee
- When returning or unmounting cancel the notification and stop the foreground service
Note: See also this issue where I'm asking to documented better the limitations and explained better the solution
I tried using the Notifee notification using asForegroundService: true, ongoing: true,autoCancel: false as explained in the main issue you opened. Could you provide a Codesandbox exemple?
I'll see what I can do since it is proprietary code. If you share your code maybe I can pinpoint it.
@Asiratlan See https://github.com/react-native-image-picker/react-native-image-picker/pull/2245