I'm using expo-image-picker to allow the user to pick and take pictures. Choosing an image from the library works as expected but when using the camera, after taking the picture the app crashes. Here is my code:
const take = async () => {
let result = await ImagePicker.launchCameraAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images,
quality: 1,
});
console.log(result.uri);
if (!result.cancelled) {
setImageUri(result.uri);
}
};
I think I have all the required permissions and the problem seems to occur only on older android devices with limited memory. Any ideas?
There is no good and easy solution.
What is happening is, when you launch the camera, it launches as a new Activity
, leaving your app mainActivity
in background.
From Android P (9) and on, the OS can kill your background activity. There is even a website just about whose implementation is worse for devs: https://dontkillmyapp.com/
Possible solutions:
ImagePicker.getPendingResultAsync
.mainActivity
but needs boring reimplementation, and don' t look as good as the manufacturer native cameras.