Library does not handle Activity re-creation by Android system
Description
On low end Android hardware (2 GB of RAM), at some point in the functioning of an application, when trying to take some pictures with the library, the Android OS will kill the host application and re-create it after the takePictures intent is finished. Applications should handle these lifecycle methods themselves, but so should the react-native-image-picker library. When Android starts killing background tasks, the picture which was last taken will not be available to the host application and the library should be able on restart to provide this to the host application. Expo-image-picker recently implemented a similar functionality here: https://github.com/expo/expo/pull/9697/files although it is not complete there as well. They only take one case into consideration, the one where the activity is killed by the OS, but not the application. I don't know if in the latter case there might be a solution in the react-native ecosystem.
How to repeat issue and example
Use the react-native-image-picker library to launch the camera (or choose image, they should behave the same). Go to "Developer options" and set to true the option to "Don't keep activities". Take a picture. The picture taken won't be available to the calling application. For the second issue (when the application gets destroyed instead of the activity), also change the "Background process limit" in "Developer options" to "No background process".
Solution
Persist the image information onHostDestroy and provide a callback for the host application to check if it was restarted and there is a pending image request. For the second issue I am not sure what solution can be applied
Additional Information
- Image Picker version: v3.0.0-vnext.3 (present in older versions as well)
- React Native version: 0.63.3
- Platform: Android
- Development Operating System: Windows
- Dev tools: Android Studio, tested on device and emulator with Android 10 OS
Note: There are multiple issues opened on this platform which are actually related to this specific particularity. The issues labeled: "Application restarts without error after taking picture" or similar titles are related to this issue that the Android OS will restart the background application if it needs to free up memory.
Source: react-native-image-picker/react-native-image-picker