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 8976685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:12:14+00:00 2026-06-15T19:12:14+00:00

I have set am activity to handle configuration changes and it works, meaning that

  • 0

I have set am activity to handle configuration changes and it works, meaning that onConfigurationChanged() is called when the orientation changes.

The activity has a button to explicitly change the orientation. When clicked, it called setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT).

Then the orientation is irrevocably set and onConfigurationChanged() is not called anymore.

How can I change the orientation when the user clicks the button while not loosing the onConfigurationChanged() callback ?

  • 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-06-15T19:12:15+00:00Added an answer on June 15, 2026 at 7:12 pm

    This is how I solved it. I am aware it is reinventing the wheel but it meets my requirement and I did not find a proper way to handle this with standard sdk tools.

    First, create an OrientationManager class that listen to orientation changes

    public class OrientationManager extends OrientationEventListener{
    private static final String TAG = OrientationManager.class.getName();
    
    private int previousAngle;
    private int previousOrientation;
    private Context context;
    private OrientationChangeListener orientationChangeListener;
    private static OrientationManager instance;
    private OrientationManager(Context context) {
        super(context);
        this.context = context;
    }
    
    public static OrientationManager  getInstance(Context context){
        if (instance == null){
            instance = new OrientationManager(context);
        }
        return instance;
    }
    
    public int getOrientation(){
        return previousOrientation;
    }
    
    public void setOrientation(int orientation){
        this.previousOrientation = orientation;
    }
    
    
    @Override
    public void onOrientationChanged(int orientation) {
        if (orientation == -1)
            return;
        if(previousOrientation == 0){
            previousOrientation = context.getResources().getConfiguration().orientation;
            if (orientationChangeListener != null){
                orientationChangeListener.onOrientationChanged(previousOrientation);
            }           
        }
        if (previousOrientation == Configuration.ORIENTATION_LANDSCAPE &&
                ((previousAngle > 10 && orientation <= 10) ||
                (previousAngle < 350 && previousAngle > 270 && orientation >= 350)) ){
            if (orientationChangeListener != null){
                orientationChangeListener.onOrientationChanged(Configuration.ORIENTATION_PORTRAIT);
            }
            previousOrientation = Configuration.ORIENTATION_PORTRAIT;
        }
    
        if (previousOrientation == Configuration.ORIENTATION_PORTRAIT &&
                ((previousAngle <90 && orientation >= 90 && orientation <270) ||
                (previousAngle > 280 && orientation <= 280 && orientation > 180))   ){
            if (orientationChangeListener != null){
                orientationChangeListener.onOrientationChanged(Configuration.ORIENTATION_LANDSCAPE);
            }
            previousOrientation = Configuration.ORIENTATION_LANDSCAPE;
        }
        previousAngle = orientation;
    }
    
    public void setOrientationChangedListener(OrientationChangeListener l){
        this.orientationChangeListener = l;
    }
    
    public interface OrientationChangeListener{
        public void onOrientationChanged(int newOrientation);
    }
    }
    

    Then in your activity implement OrientationChangeListener and override onOrientationChanged():

    public class MyActivity extends Activity implements OrientationChangeListener{
    
        private OrientationManager orientationManager;
    
        @Override
        public void onCreate(Bundle b){
            orientationManager = OrientationManager.getInstance(this);
            orientationManager.setOrientationChangedListener(this);
    
        }
    
    @Override
    public void onOrientationChanged(int newOrientation) {
        orientation = newOrientation;
        if (newOrientation == Configuration.ORIENTATION_LANDSCAPE){
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
            setLandscapeConfig();
        }else{
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            setPortraitConfig();
        }
    }
    

    So I don’t use onConfigurationChanged anymore but keep the following line in the Manifest:
    android:configChanges=”orientation|screenSize”

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

Sidebar

Related Questions

How to handle screen orientation without rotating screen? I have override onConfigurationChanged in my
I have an activity which handles configuration changes. But now i have to change
I have activity in my application and i have set android:configChanges=orientation in my menifest
I have a problem with a replicator activity in a workflow. I have set
I have an Activity with a ListView, I set the background image to the
I have imageView in activity. How I can set position this imageView in my
I have set the eclipse java formatter to wrap lines that exceed 120 characters
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I have set up intent filters to handle certain email links with my app.
In a simple inventory management app i have an activity to handle assigning equipment

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.