Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Self-Destructing Message Android App Capturing Photos and Videos Saving a Photo to the Gallery

Marcel Rob
Marcel Rob
10,282 Points

The Uri memeber variable gets set to null when onActivityResult gets called

so , the mMediaUri gets correctly set to the path in which the picture will be saved after it is taken , but after i take the picture and the device gets back in onActivityResult the mMediaUri variable is null and the app crashes . I think this is because when the camera starts the screen rotates for some reasons . I have read somewhere that on screen roatation the activity recreats . I think that is the point where the mMediaUri loses its value . How can I solve this ??

1 Answer

You should really post some code as well as the error. As for the screen orientation, a possible solution is to make the app stay in portrait mode only. Do do this, add the android:screenOrientation:="portrait" property to your manifest.

Marcel Rob
Marcel Rob
10,282 Points

the only way I coul make it work was by using another app to take the photo , I downloaded the camera application from google and it worked fine . There's something with the camera app from the galaxy s4 that makes the app crash , when the camera app ends and the onActivityResult gets called the variables are reset , that doesn't happen with the camera app from google