为什么在使用FLAG_ACTIVITY_REORDER_TO_FRONT时不能禁用动画来更改活动?

时间:2018-12-27 04:33:09

标签: java android android-studio android-intent

在我的游戏中,当用户决定将屏幕从“消息”屏幕切换到“个人资料”屏幕时,我要确保用户可以切换屏幕并保持先前​​的活动。

所以我有这段代码:

Intent intent = new Intent(this, Profile.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(intent, 0);
overridePendingTransition(0, 0);

它起作用,除了它仅在第一次从屏幕切换时禁用动画,此后不起作用。它播放动画,但我不想要那个。

我该如何解决?

2 个答案:

答案 0 :(得分:0)

您可以按照@DKV的建议禁用动画。

代替这个

Intent intent = new Intent(this, Profile.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivityIfNeeded(intent, 0);
overridePendingTransition(0, 0);  // remove this line

尝试使用此

Intent intent = new Intent(this, Profile.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityIfNeeded(intent, 0);

请注意

  

addFlags

不是

  

setFlags

答案 1 :(得分:0)

我通过遵循https://github.com/ahmedabdo97/bootstrap4/blob/master/Error.png的答案来做到这一点。

创建未指定动画的样式: <item name="android:windowAnimationStyle">@null</item>

然后将其用作清单中该活动的主题。