0

I would like to add an animation before the opening of a new Android Empty Activity. Something like a chroma-keyed video played on top of the current activity and at the end of it, the secondary activity opens up.

ankuranurag2
  • 2,300
  • 15
  • 30
Sad Hyena
  • 291
  • 3
  • 16

2 Answers2

1

You create a splash activity that includes your animation, and you implement an AnimationListener. Inside the method onAnimationEnd() you create the intent that takes you to the second activity. Don't forget to set the splash activity as the Launcher activity on your manifest.

animationObject.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        Intent intent = new Intent (SplashActivity.this, MainActivity.class);
        startActivity(intent);    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});

EDIT: if you want to play a video with media player instead you use a playback listener and run the same intent from onCompletion()

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
  • thanks for the answer...is it possible to chroma-key a video? like green screen – Sad Hyena Dec 11 '18 at 11:23
  • do you have a video that's already filmed on green screen and want to edit the background? not sure I understand what you have and what you want to achieve?! – Nikos Hidalgo Dec 11 '18 at 11:27
  • is that functionality part of your app? if so check this answer https://stackoverflow.com/a/40278174/10300673 If not you just use another app from the play store to create your video and then embed the final product in your activity – Nikos Hidalgo Dec 11 '18 at 11:40
0

After your startActivity method use the overridePendingTranistion and put the animations in it

 button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(ActivityA.this, ActivityB.class));
                overridePendingTransition(R.anim.enter, R.anim.exit);
            }
        });

The xml animations are as follows enter.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="100%"
        android:fromYDelta="0%"
        android:toXDelta="0%"
        android:toYDelta="0%" />
</set>

exit.xml:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
    <translate
        android:duration="500"
        android:fromXDelta="0%"
        android:fromYDelta="0%"
        android:toXDelta="-100%"
        android:toYDelta="0%" />
</set>
Rohit Sharma
  • 1,384
  • 12
  • 19