使用 FLAG_ACTIVITY_REORDER_TO_FRONT 时 overridePendingTransition 不起作用 [英] overridePendingTransition does not work when FLAG_ACTIVITY_REORDER_TO_FRONT is used

查看:45
本文介绍了使用 FLAG_ACTIVITY_REORDER_TO_FRONT 时 overridePendingTransition 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在堆栈中有两个活动,为了显示它们,我使用了 FLAG_ACTIVITY_REORDER_TO_FRONT.到目前为止一切顺利,当我想使用 overridePendingTransition 为 Activity 带来动画时出现问题.

I have two activities in the stack, in order to show them I use FLAG_ACTIVITY_REORDER_TO_FRONT. So far so good, the problem comes when I want to bring the activity with an animation using overridePendingTransition.

Intent i = new Intent(ActivityA.this, ActivityB.class);
i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
ActivityA.this.startActivity(i);
overridePendingTransition(R.anim.transition_to_right, R.anim.transition_to_left);

转换未显示,但是,如果未将标志添加到意图(删除第 2 行),则没有问题.

The transition is not shown, however, if the flag is not added to the intent (removing line 2) then there is no problem.

是否可以通过动画将活动置于首位?

Is it possible to bring an activity to front with an animation?

非常感谢!

推荐答案

实际上,使用 REORDER_TO_FRONT 时正确的解决方案是在您要打开的活动的 onNewIntent() 方法中调用 overridePendingTransition.

Actually the right solution when using REORDER_TO_FRONT is to call overridePendingTransition in the method onNewIntent() of the activity you are going to open.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}

替换为您的过渡.

如果您需要有选择地替换过渡,您可以在您的意图中添加一个额外的内容,并在 onNewIntent() 中检查它以决定要做什么.

If you need to selectively replace the transition you can add an extra in your intent and check it in the onNewIntent() to decide what to do.

如果您不知道将要打开的转换(例如,如果您没有明确指定),则这不适合,否则这是正确的解决方案.

This is not suitable if you don't know the transition that will be opened (if you don't specify it explicitly for example) but otherwise is the right solution.

这篇关于使用 FLAG_ACTIVITY_REORDER_TO_FRONT 时 overridePendingTransition 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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