Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7413755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:57:13+00:00 2026-05-29T06:57:13+00:00

I am using the XML tag android:configChanges=orientation|keyboardHidden|keyboard and the following code to detect device

  • 0

I am using the XML tag

android:configChanges="orientation|keyboardHidden|keyboard"

and the following code to detect device orientation changes and change layouts:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    disp = getWindowManager().getDefaultDisplay();
    swidth = disp.getWidth();
    sheight = disp.getHeight();
    parent.removeAllViews();
    parent = new RelativeLayout(this);
    if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
        layoutPortrait();
    else
        layoutLandscape();
}

This works fine going form portrait to landscape. But, for whatever reason, going from landscape to portrait (starting in landscape or switching to it then back) doesn’t change the screen back to portrait.

Through the use of Log messages I’ve determined that after being in Landscape mode, the Display and Configuration classes DO NOT UPDATE. They remain holding the same orientation/length/width values as when the device was in landscape.

Does anyone have any idea why this is?

Additional Code (requested by contributor)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    disp = getWindowManager().getDefaultDisplay();
    swidth = disp.getWidth();
    sheight = disp.getHeight();
    int ornt;
    if(swidth == sheight)
        ornt = Configuration.ORIENTATION_SQUARE;
    else if(swidth < sheight)
        ornt = Configuration.ORIENTATION_PORTRAIT;
    else if(swidth > sheight)
        ornt = Configuration.ORIENTATION_LANDSCAPE;
    else
        ornt = Configuration.ORIENTATION_UNDEFINED;
    parent = new RelativeLayout(this);
    labelOne = new TextView(this);
    labelOne.setText("Temperature");
    labelOne.setId((int)(Math.random()*Integer.MAX_VALUE));
    temp = new EditText(this);
    temp.setSingleLine(true);
    temp.setBackgroundColor(Color.WHITE);
    temp.setTextColor(Color.BLACK);
    temp.setId((int)(Math.random()*Integer.MAX_VALUE));
    labelTwo = new TextView(this);
    labelTwo.setText("Humidity(%)");
    labelTwo.setId((int)(Math.random()*Integer.MAX_VALUE));
    humidity = new EditText(this);
    humidity.setSingleLine(true);
    humidity.setBackgroundColor(Color.WHITE);
    humidity.setTextColor(Color.BLACK);
    humidity.setId((int)(Math.random()*Integer.MAX_VALUE));
    output = new TextView(this);
    output.setBackgroundColor(Color.WHITE);
    output.setTextColor(Color.BLACK);
    output.setId((int)(Math.random()*Integer.MAX_VALUE));
    submit = new Button(this);
    submit.setText("Calculate");
    submit.setId((int)(Math.random()*Integer.MAX_VALUE));
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
              Double result = Calculate.calculate(getInputs());
              if(result !=null) {
                String answer = String.format("%,.1f",result);
                if(f.isChecked()) {
                    output.setText(answer + "°F");
                } else {
                    output.setText(answer + "°C");
                }
              }
        }
    });
    f = new RadioButton(this);
    f.setText("Fahrenheit");
    c = new RadioButton(this);
    c.setText("Celsius");
    rg = new RadioGroup(this);
    rg.setOnCheckedChangeListener(new ListenForMode());
    rg.addView(f);
    rg.addView(c);
    rg.setId((int)(Math.random()*Integer.MAX_VALUE));
    f.setChecked(true);
    if(ornt == Configuration.ORIENTATION_PORTRAIT || ornt == Configuration.ORIENTATION_SQUARE)
        layoutPortrait();
    else
        layoutLandscape();
}

Final Update

Issue is with the emulator not responding correctly to the orientation changes. I changed the onConfigurationChanged(…) orientation checking to use the condition width < height for portrait and all else landscape. This works perfectly on my Android device.

Thanks to all contributors to this question!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:57:14+00:00Added an answer on May 29, 2026 at 6:57 am

    If it happens on emulator, then it’s OK – emulator behaves a little bit weird in sense of configuration changes. I have been trying to solve similar problem, unless I noticed that the app worked fine on a real device.

    It seems that the emulator ignores the android:configChanges="orientation" attribute, but in a bit strange way: it does force the configuration change but doesn’t call onConfigurationChanged(..) method every time it should be called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using XML serialization in C#, I use code like this: public MyObject LoadData()
I'm using file main.xml to design UI in Android. I don't know why the
I am using Android global variable example. How do I add another application tag
i am working with android and using xmlpullparser in android to parse an xml
I have been using this code to parse xml till now. Its was working
This is the code which I was using for android 2.3 . and it
I'm trying to learn to use xml in Java (Android platform, using Eclipse and
I am using my usual code to receive a feed in XML and store
i'm using xmlpullparser in android to parse an xml document that looks like :
I'm trying to reuse some layout components in android application using <include> tag. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.