How to finish an activity when transition is done Android

余生颓废 提交于 2019-12-06 15:42:12

The answer in the link you provided suggests to create a variable at the top of your activity

Boolean mShouldFinish = false;

Then after you start your transition to the next activity (after startActivity(ctx,intent, bundle)) add:

mShouldFinish = true;

And add override the onStop method with:

@Override
public void onStop() {
    super.onStop();
    if(mShouldFinish)
         finish();
}

I have just shared my answer here. Use supportFinishAfterTransition();

Guys found a solution to this, instead of using this code to the transition

if (Build.VERSION.SDK_INT >= 21) {
                    TransitionInflater inflater = TransitionInflater.from(LoginActivity.this);
                    Transition transition = inflater.inflateTransition(R.transition.fade_transition);
                    TransisitonTime = transition.getDuration()*2;
                    getWindow().setExitTransition(transition);
                }

                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(LoginActivity.this);

i used this instead

overridePendingTransition(R.animator.fade_in,
                        R.animator.fade_out);

with these xml files

fade_in.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="2000"/>
</set>

fade_out.xml:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="1.0" android:toAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="2000"/>
</set>

this way i can do the fade in and fade out transition when the finish() is called

kudos to @Droidman for pointing me in the right direction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!