react-native-image-picker icon indicating copy to clipboard operation
react-native-image-picker copied to clipboard

The app get restared when I press confirm button afer I take a photo with the camera [🐛]

Open simancaaswork opened this issue 2 years ago • 19 comments

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
  1. Open camera
  2. Take a photo
  3. Press confirm button

Additional Information

  • Image Picker version: "^4.7.3"
  • React Native version: "0.68.1"
  • Platform: Android
  • Development Operating System: MacOS

simancaaswork avatar Apr 20 '22 15:04 simancaaswork

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

shakawy avatar May 10 '22 15:05 shakawy

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)

zachnicoll avatar May 17 '22 02:05 zachnicoll

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 avatar May 19 '22 03:05 josephgodwinkimani

@josephgodwinkimani Yes. My app is running RN 0.67 and image-picker works fine

shakawy avatar May 19 '22 12:05 shakawy

i upgraded to React Native 0.68.x and im getting crash when take a phone from camera

shakawy avatar Jun 07 '22 15:06 shakawy

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.

berehovyi avatar Jun 13 '22 09:06 berehovyi

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

josephgodwinkimani avatar Jun 15 '22 07:06 josephgodwinkimani

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 .

berehovyi avatar Jun 15 '22 12:06 berehovyi

i hope this issue get fixed by the maintainers in the next release

shakawy avatar Jun 29 '22 08:06 shakawy

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

Goostavo avatar Dec 15 '22 19:12 Goostavo

I have same problem with smartphone from company Xiaomi. After restarting my smartphone, then the bug dissapeared.

akbako avatar Jan 15 '23 04:01 akbako

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.

sierraleonez avatar Feb 06 '23 04:02 sierraleonez

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:

  1. Open your app
  2. Open the camera
  3. Turn on 'Don't keep activities'.
  4. 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

Goostavo avatar Feb 07 '23 13:02 Goostavo

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?

SamWhitby avatar Apr 28 '23 04:04 SamWhitby

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. Register your foreground service with notifee
  2. Display an ongoing notification with notifee
  3. 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

dprevost-LMI avatar Nov 10 '23 14:11 dprevost-LMI

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:

  1. Open your camera. (The notifee will pop up also)
  2. 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".
  3. 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.

Goostavo avatar Nov 10 '23 14:11 Goostavo

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. Display 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

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?

Asiratlan avatar Nov 14 '23 17:11 Asiratlan

I'll see what I can do since it is proprietary code. If you share your code maybe I can pinpoint it.

dprevost-LMI avatar Nov 14 '23 17:11 dprevost-LMI

@Asiratlan See https://github.com/react-native-image-picker/react-native-image-picker/pull/2245

dprevost-LMI avatar Nov 23 '23 03:11 dprevost-LMI