Android app restart when camera to take photo
See original GitHub issueIts working well on the ios all version. its also working on the android 11. but android 10 work only gallery picker, fail in camera selection. problem is all version we are use in a project “react-native-image-picker”: “^3.1.3”, also use “react-native-image-picker”: “^1.1.0”, another project but issue is same happen.
//v: 1 code
const options = {
title: “Upload Profile Image”,
quality: 0.5,
maxWidth: 400,
maxHeight: 400,
storageOptions: {
skipBackup: true,
cameraRoll: true,
waitUntilSaved: true,
path: “images”,
},
cancelButtonTitle: “Cancel”,
takePhotoButtonTitle: “Open Camera”,
chooseFromLibraryButtonTitle: “Open Library”,
};
ImagePicker.showImagePicker(options, (response) => {
if (response.didCancel) {
console.log(“User cancelled image picker”);
} else if (response.error) {
console.log("ImagePicker Error: ", response.error);
} else if (response.customButton) {
console.log("User tapped custom button: ", response.customButton);
} else {
console.log(response, “response”);
this.setState({ imageDetails: response });
var imageData = data:${response.type};base64,${response.data}
;
console.log(“imageData”, imageData);
this.setState({ loading: true });
this.setState({ imageData: imageData });
}
});
//v: 3 code
if (Platform.OS === ‘ios’) { const options = { includeBase64: true, maxWidth: 400, maxHeight: 400, }; launchCamera(options, (response) => { if (response.uri) { setPhoto(response); updateImageToServer(response); } }); } else { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.CAMERA, { title: Languages.title, message: Languages.message, buttonNeutral: Languages.buttonNeutral, buttonNegative: Languages.buttonNegative, buttonPositive: Languages.buttonPositive, }, ); if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log(‘Camera permission given’); const options = { includeBase64: true, maxWidth: 400, maxHeight: 400, }; launchCamera(options, (response) => { if (response.uri) { setPhoto(response); updateImageToServer(response); } }); } else { console.log(‘Camera permission denied’); } } catch (err) { console.warn(err); } }
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
@AdminDevo Your reply makes sense, however how to explain that for some library even if it goes in background it never crashes when resuming? (so many libraries out there deals with camera and gallery picker, yet this one is the only one who seems to crash regularly on many devices) Why do we stick with this library then, you may ask? Because it remains the most stable, well maintened and widely used so far, in spite of this issue. And I do believe this crashing issue here is the biggest one with this library, I would love to see it fixed once and for all after all these years.
Finally I got the solution. Somebody told manage “Don’t Keep Activity” in Developer Option, someone told battery Saver Restriction. Everything was wrong and not workaround.
Let us tell you that all versions of this library run, there is no problem with them, neither Android nor iOS. Solution:- you have need updated Android version or if update is not available then click on three dot to install latest package. After this you will see that no application will restart from background on home and then open. And in the same way, now you will not get reopen app after the camera photo take. Actually sometimes our Android OS gets corrupted, this was the reason for this.