android – React native image picker causes application to restart without error
Reverting with information regarding this issue. Full history of discussions can be followed here: https://github.com/react-native-image-picker/react-native-image-picker/issues/1502.
The summary is as follows: the issue happens on devices where the used memory is close to maximum available memory and is happening with almost all react-native libraries that launch a new Activity for camera (expo-image-picker, react-native-crop-image-picker, etc.). When this happens the Android OS has the ability to kill background tasks to reclaim memory (Some proprietary versions of Android can kill background tasks more aggresively than others). When the user launches a new intent to open the camera, the main React native application goes in background and can be killed by Android OS (and re-created by Android OS when the user returns to the initial application). When the application is killed, all information is lost unless you have a mechanism to persist state when going in background. Usually, the Android OS will provide the last Activity result (in this case the image taken with the camera application) to the calling application which in this case is the React Activity. Unfortunately there is an issue with how React native handles this onActivity result when the React Context is destroyed and later re-created, issue that can be followed here: https://github.com/facebook/react-native/issues/30277.
Until that issue is fixed, this problem will persist, mostly in the case of low-memory devices. For anyone not looking for fancy camera options, just the ability to take pictures or start video recording, you can use the React Native Camera library (https://github.com/react-native-camera/react-native-camera) to overcome this issue with activity being re-created by the Android system. The difference is that the RNCamera library does not launch a new Android activity (just embeds the camera wherever you specify it to do it) which means that your current React application will remain active, even when taking picture/recording video.