[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:

 public void onActivityCreated(Bundle savedInstanceState) {
    setRetainInstance(true); // Fixes possible rotations after taking picture with camera


<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

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 )

Connecting to %s