34

I am calling an Activity B from Activity A, which contains a Video View using the following code :

Intent intent = new Intent(this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, 0);

I am using Intent.FLAG_ACTIVITY_NO_ANIMATION to avoid transition animation while new activity is being called. But its not working for me and a black screen is coming while the transition. Is there any way to avoid this transition animation and black screen, so that the user will not come to know that the video view is being called in a new screen?

Shruti
  • 1
  • 13
  • 55
  • 95
Timson
  • 1,337
  • 3
  • 19
  • 32
  • Try this: http://stackoverflow.com/questions/6972295/switching-activities-without-animation Or this: http://stackoverflow.com/questions/2286315/disable-activity-slide-in-animation-when-launching-new-activity – Awais Tariq Mar 07 '12 at 06:29

3 Answers3

72

Try calling:

Intent intent = new Intent(this, B.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityForResult(intent, 0);
overridePendingTransition(0,0); //0 for no animation
technofunc
  • 779
  • 5
  • 7
  • This worked for me also thanks! Quick question, why are you using startActivityForResult() instead of just startActivity()? I get the same desired result (no animation) with both? – Evan McEwen Apr 04 '13 at 20:04
  • 4
    @EvanM You don't have to use startActivityForResult(). You'd only use it if you wanted to get a "result" back from the next Activity. – Karim Varela Dec 11 '13 at 19:45
  • just using `intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);` worked for me. – Micro Jul 29 '15 at 17:19
  • 3
    on marshmallow don't work without ``overridePendingTransition`` – Vlad Jun 07 '16 at 15:35
  • @Micro sorry but only the original answer worked! Seems `overridePendingTransition` is a must. – Hamzeh Soboh Oct 08 '17 at 08:19
9

if you want to do it for all activities then do it in this way:

switching activities without animation

Just assign style with no animation to each activity in manifest.

Or through code do it in this way:

Disable activity slide-in animation when launching new activity?

Community
  • 1
  • 1
Awais Tariq
  • 7,724
  • 5
  • 31
  • 54
0

Took me quite some time to figure it out...

to support overriding transition when coming back from another Activity:

use overridePendingTransition in your Activity onResume.

    override fun onResume() {
        super.onResume()

        // disable transition when coming back from an activity
        overridePendingTransition(0, 0)
    }