How to override animation when entering in PIP mode in android

742 Views Asked by At

My PIPActivity has only one image view and I am entering in PIP mode in onCreate() i.e PIPActivity is there only to show image in PIP mode. Now when I am starting PIPActivity there is some animation that slowly transitions into PIP mode. During this transition, the image is getting stretched weirdly. To avoid this how can stop the animation when entering PIP mode? I have already tried

  • In onCreate() calling overridePendingTransition(0, 0).
  • Adding Intent.FLAG_ACTIVITY_NO_ANIMATION while launching activity.
  • Setting <item name="android:windowAnimationStyle">@null</item> in activity theme.
2

There are 2 best solutions below

0
On

You may want to look at ActivityOptions and its various methods.

Create an ActivityOptions specifying a custom animation to run when the activity is displayed.

ActivityOptions options = ActivityOptions.makeCustomAnimation(MainActivity.this, 0, 0);
startActivity(intent, options.toBundle());

Or by using setExitTransition and/or setSharedElementExitTransition.

getWindow().requestFeature(android.view.Window.FEATURE_ACTIVITY_TRANSITIONS);

//These functions define the exit transition for the calling activity.
getWindow().setExitTransition(null);
getWindow().setSharedElementExitTransition(null);

setContentView(R.layout.mainActivity);

NOTE

Implement one of these in a launcher activity and NOT in PIPActivity.

0
On

Use this method and implement it on launcher activity:

getWindow().requestFeature(android.view.Window.FEATURE_ACTIVITY_TRANSITIONS);
getWindow().setExitTransition(null);
getWindow().setSharedElementExitTransition(null);
setContentView(R.layout.mainActivity);