[Android SDK] Fragment getting rotated after camera capture

This has been a painful issue in various devices (specially Samsungs).
After taking a picture, even with the Activity locked to portrait mode, the device was forcing various rotations, destroying the whole Fragment, and all views inside.

The only solution that worked for me was:

MyCameraFragment.java:
 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setRetainInstance(true); // Fixes possible rotations after taking picture with camera
 }

AndroidManifest.xml:

<activity name=".ui.activity.MyCameraActivity" configChanges="screenSize|orientation"/>

Note that MainActivity should be the activity containing the mentioned Fragment on its layout.

Hope it saves time for someone! I wasted several valious hours with this

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s