Disable default animation from Portrait to Landscape

Viewed 16066

I have an app with several 'normal' activities which can run on either landscape or portrait. They are designed for and mostly used on portrait.

This app has one single activity which uses the camera and is locked on landscape. I 'simulate' this activity is on portrait by rotating images and texts 90 degree, so it looks like the rest of activities.

On some device, such as Samsung Galaxy Tab 7 and Galaxy S3, a rotation animation is shown when going from a normal portrait activity to camera landscape activity and back. This is confusing for user because landscape activity simulates being on portrait.

Is there a way to remove this rotation animation? Ideally I'd like to change to default portrait to portrait animation, but just removing rotation animation would be enough.

I've tried

overridePendingTransition(0, 0);

an other variations of that method without success.

[ADDED]

Following suggestions by @igalarzab, @Georg and @Joe, I've done this (still with no luck):

  • Added android:configChanges="orientation|screenSize" to Manifest
  • Added onConfigurationChanged
  • Created a dummy animation which does nothing and added overridePendingTransition(R.anim.nothing, R.anim.nothing);

I had these results:

  • onConfigurationChanged is called only when rotating same Activity (Activity A on portrait -> Activity A on landscape). But it's not called when going from Activity A on portrait -> Activity B on landscape
  • This prevented Activity from being restarted when rotating, but it did NOT removed rotation animation (tested on Galaxy S3, Galaxy Nexus, Galaxy Tab 7.0 and Galaxy Tab 10.1)
  • overridePendingTransition(R.anim.nothing, R.anim.nothing); removed normal transitions (portrait->portrait and landscape->landscape) but it didn't removed rotation animation (portrait->landscape and vice versa).

[VIDEO]

I've uploaded a video that shows animation I want to disable. This happens when changing from camera activity (locked to landscape) to other activity while holding phone on portrait:

http://youtu.be/T79Q1P_5_Ck

10 Answers
android:rotationAnimation="seamless"

add this attribute in activity will reduce animation when rotate. I try to find it when i want to make smooth camera app

Successfully checked on: Java - Android 9 (Pie) - Android Studio 4.1.3 - Huawei P10

For six months I could not solve this need. The problem was in the unassigned flag "FLAG_FULLSCREEN" in code.

First step MainActivity.java:

public class MainActivity {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    /* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
    setRotationAnimation(); 
  }

  private void setRotationAnimation() {
    int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    winParams.rotationAnimation = rotationAnimation;
    win.setAttributes(winParams); 
  }

  public void Button (View view) {
    // Connected to android:onClick="Button" in XML.
    Intent intent = new Intent(MainActivity.this, MainActivity2.class);
    startActivity(intent);
  }
}

Next step MainActivity2.java:

public class MainActivity2 {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    /* getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN); */ // If the animation still is, try applying it.
    setRotationAnimation(); 
  }

  private void setRotationAnimation() {
    int rotationAnimation = 
       WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    winParams.rotationAnimation = rotationAnimation;
    win.setAttributes(winParams); 
  }

  public void Button (View view) {
    Intent intent = new Intent(MainActivity2.this, MainActivity.class);
    startActivity(intent);
  }
}

Next step styles.xml:

<resources>
  <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
      <item name="android:windowFullscreen">true</item>
  </style>
</resources>

Simple things I understood: You must first anywhere start "setRotationAnimation()", before running activity2. When start activity2 you have to run in it "setRotationAnimation()". Works incorrectly.

Related