question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android app restart when camera to take photo

See original GitHub issue

Its 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:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
pierroocommented, Apr 15, 2022

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

4reactions
AdminDevocommented, Feb 18, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

App restart? after photo taking or selection using native camera
When I take a photo or select photo with the using of the native camera plugin, the app will auto reload. It happens...
Read more >
PhoneGap camera restarts the application - Stack Overflow
It occurs because when the camera is triggered, the android activity goes background (onStop state), waiting for the camera to take the picture....
Read more >
[Camera Plugin] Application crashes and restarts when taking ...
When capturing an image with the Camera plugin it crashes everytime I take a picture and the app restarts. This only happens on...
Read more >
Why does my Android phone restart when I open the camera ...
There are a few reasons why your Android phone might restart when you open the camera app. One possibility is that your battery...
Read more >
Complete Guide to Fix “Unfortunately, Camera Has Stopped ...
One of the easiest ways to fix unfortunately, camera has stopped on Android is restarting the camera or device. If you want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found