user1513687
user1513687

Reputation: 173

Loading picture from camera into ImageView

In my app, I have it so that when the user clicks on the Camera button it takes him to the camera using an intent.

He then takes the picture and it should load it back into the ImageView I have on the same screen as the Camera button.

I think something is wrong with my screen orientation. When I load the camera view it switches to horizontal orientation, and when it closes it switches back to vertical orientation and my whole screen resets back to default.

This is the error I get in logcat:

12-03 20:14:38.440: E/SpannableStringBuilder(15134): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length

Any ideas?

EDIT:

Here is what happens:

I put your alls code in, but it isn't helping.

Upvotes: 0

Views: 768

Answers (3)

user1513687
user1513687

Reputation: 173

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

All I did was add that line of code and it worked perfectly.

Upvotes: 0

Himanshu Virmani
Himanshu Virmani

Reputation: 2460

Also the point to be noted is that camera is by default in android works in landscape mode only. So no matter what you screen orientation is, the camera will launch in horizontal mode only. Also as above mentioned do

android:configChanges="orientation"

And handle this in your activity be using the below callback

@Override
public void onConfigurationChanged(Configuration newConfig) {       
    super.onConfigurationChanged(newConfig);

}

Upvotes: 1

dtheo
dtheo

Reputation: 133

The reason that your activity gets reseted is because of the screen orientation change made by the camera intent.

You can put android:configChanges="orientation" inside your activity in the androidManifest.xml

Once you have that, it would not destroy and recreate your activity.

Please see http://developer.android.com/guide/topics/manifest/activity-element.html#config for more details

Upvotes: 0

Related Questions