Software Sainath
Software Sainath

Reputation: 1050

Change Layout in Landscape with out destroying and recreating Activity

Hi Everyone iam new to android and stuck with the orientation problem i need to display separate layout in landscape and portrait which i designed separately and placed in layout-large and layout-large-land folders now i need to change layout when device is rotated to landscape with out destroying and recreating the Activity

please help me get out of this problem

Thanks in Advance

Upvotes: 3

Views: 2040

Answers (3)

moDev
moDev

Reputation: 5258

Replace

layout-large-land

with

layout-land-large

Prevent activity from recreating/destroying

Add attribute android:configChanges="orientation" to the activity declaration in the AndroidManifest.xml file.

The purpose of the android:configChanges attribute is to prevent an activity from being recreated when it's really required.

Let me know if it works for you..

Upvotes: 0

MuraliGanesan
MuraliGanesan

Reputation: 3261

Try this,

Add this code in your mainfest.xml each and every activity.

android:ConfigChanges="keyboardHidden|orientation"   

Upvotes: -1

Budius
Budius

Reputation: 39836

my advice as a long time Android programmer is:

Don't do it!

Let the activity be destroyed and re-built with the correct layout.

Just search and research on all the several methods of keeping the data during orientation changes and apply them to your specific case. Below a few to illustrate:

  1. the onCreate(Bundle) receives that bundle that contains information saved during onSavedInstances(Bundle);
  2. User a fragment without a UI (do not call onCreateView) and set it to be retained across rotation with setRetainInstance(true) and use it to remember the data
  3. use the Loader pattern to automatically receive the data it was generated on the previous activity

Upvotes: 3

Related Questions