Android转换完成后如何完成活动 [英] How to finish an activity when transition is done Android

查看:241
本文介绍了Android转换完成后如何完成活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在两个活动之间的转换完成后结束之前的活动

i want to end a previous activity after the transition between 2 activities is completed

我试过 ActivityCompat.finishAfterTransition(this); 但它实际上在转换完成之前完成了活动

i have tried ActivityCompat.finishAfterTransition(this); but it actually finishes the activity before the transition is done

我已经研究过此解决方案之前,但我无法理解它的答案,如果有人能解释如何结束,它会膨胀转换完成后的活动

i have looked into this solution before but i couldn't understand the answer to it , it would be swell if someone can explain how to end an activity after the transition is done

更新:

我刚尝试启动下一个这样的活动

i just tried starting the next activity like this

Intent intent = new Intent(LoginActivity.this, TaskActivity.class);
                    startActivity(intent);

onStop代码将被激活,但当我使用此

the onStop code will be activated but when i use this

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(LoginActivity.this);
                Intent intent = new Intent(LoginActivity.this, TaskActivity.class);
                startActivity(intent,options.toBundle());

onStop不会被激活所以我应该手动激活它,如果是这样的话,建议

the onStop wouldn't be activated so should i manually activate it and if so is it recommended

推荐答案

Guys找到了解决方案,
而不是使用此代码进行转换

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);

我用的是

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

包含这些xml文件

fade_in。 xml:

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:

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>

这样我可以在完成时进行淡入和淡出过渡()被称为

感谢 @Droidman 指出我正确的方向

这篇关于Android转换完成后如何完成活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆