Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

308
Views
onConfigurationChanged not called for 180 and 270 degrees

I have faced a strange issue (or maybe unexpected behavior) on my Android device.

The problem is that I am listening for configuration changes in my DialogFragment like this:

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Do something secret here :)
}

I added android:configChanges to the Activity which is responsible for showing the dialog fragment

<activity
    android:name=".SecretActivity" 
    android:configChanges="orientation|screenSize"
    android:windowSoftInputMode="adjustResize" />

and indeed I am getting callbacks from the system when I am rotating device, but not in all cases. As you can see in the picture onConfigurationChanged( ) called only when I am rotating 90 degrees, and also 360, in other cases it is not called.

Is this an expected behavior? If yes, how I can detect all rotations (90, 180, 270, 360)?

enter image description here

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

If you have an activity with unspecified screen orientation, devices generally ignore 180° rotation and only support one landscape direction.

To support all directions, add an explicit screenOrientation attribute to you activity manifest entry: user or sensor, depending on whether you want to support device orientation locking by user or not.

over 4 years ago · Santiago Trujillo Report

0

OrientationEventlistener won't work when the device isn't rotating/moving.

I find display listener is a better way to detect the change.

 DisplayManager.DisplayListener mDisplayListener = new DisplayManager.DisplayListener() {
    @Override
    public void onDisplayAdded(int displayId) {
       android.util.Log.i(TAG, "Display #" + displayId + " added.");
    }

    @Override
    public void onDisplayChanged(int displayId) {
       android.util.Log.i(TAG, "Display #" + displayId + " changed.");
    }

    @Override
    public void onDisplayRemoved(int displayId) {
       android.util.Log.i(TAG, "Display #" + displayId + " removed.");
    }
 };
 DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE);
 displayManager.registerDisplayListener(mDisplayListener, UIThreadHandler);

onDisplayChanged triggers only exactly when getRotation() changes. OrientationEventListener on the other hand triggers constantly in real time and even before getRotation() changes, leading to completely wrong screen rotation values when doing a 180° turn from a perspective.

over 4 years ago · Santiago Trujillo Report

0

Hmm, check manifest, add this/modify

android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!