简体   繁体   English

如何在清除活动堆栈Android上停止过渡动画?

[英]How to stop transition animation on clear activity stack android?

A white screen blinks for few milliseconds when I simply go from login activity to Main activity with following clear back stack code. 当我简单地从登录活动转到Main活动并遵循以下清晰的堆栈代码时,白屏闪烁几毫秒。

Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
overridePendingTransition(0, 0);

If I just make the startActivity without Flags (or say without clear backstack) 如果我只是使startActivity不带标志(或者说不带清晰的后退堆栈)

overridePendingTransition(0, 0);

It doesn't blink with white screen. 白屏不闪烁。

But I have to clear back stack and start a new activity with NO transition animation. 但是我必须清除后退堆栈,并以没有过渡动画的方式开始新的活动。 So it doesn't blink/appear in white screen for few milliseconds. 因此,它在几毫秒内不会闪烁/不会出现在白屏中。

Looking forward to get a perfect answer soon. 期待很快得到一个完美的答案。 Cheers ! 干杯!

Try setting noHistory="true" for login activity in the manifest and start HomeActivity without any flags. 尝试在清单中为登录活动设置noHistory="true" ,然后启动没有任何标志的HomeActivity This should solve your problem. 这应该可以解决您的问题。

Don't use Intent.FLAG_ACTIVITY_NEW_TASK . 不要使用Intent.FLAG_ACTIVITY_NEW_TASK If you want to clear the backstack (and assuming your login Activity is the only one in the stack), just finish the current Activity: 如果要清除后退堆栈(并假设登录Activity是堆栈中唯一的登录Activity ),只需finish当前活动:

Intent intent = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(intent);
overridePendingTransition(0, 0);
finish();

Intent.FLAG_ACTIVITY_NEW_TASK is likely the cause of the flash since it requires you to create a whole new "task" (which is a collection of Activities with a given history) rather than just reusing the current one. Intent.FLAG_ACTIVITY_NEW_TASK可能是导致闪烁的原因,因为它要求您创建一个全新的“任务”(这是具有给定历史记录的“活动”的集合),而不仅仅是重用当前的任务。 It's almost like navigating to another app at that point. 那时几乎就像导航到另一个应用程序一样。

As I have mentioned in the question that startActivity without using flags makes no blink and showing white screen. 正如我在问题中提到的,不使用标志的startActivity不会闪烁并显示白屏。

So I choose that. 所以我选择了。

Now the problem is to clear the stack of 1st Login activity when I am into Main Activity. 现在的问题是,当我进入主活动时,要清除第一登录活动堆栈。

I resolved it by setting the context of Login activity into Application class using setter and getter method. 我通过使用setter和getter方法将Login活动的上下文设置为Application类来解决它。

And Whenever You reached to Main Activity. 每当您到达主要活动时。 It will check whether you have the context in Application class by getter method. 它将通过getter方法检查Application类中是否有上下文。

If it's a yes and is a login activity then make the context.finish which will clear the back-stack by removing the login activity from Main Activity. 如果是,并且是登录活动,则进行context.finish,这将通过从Main Activity中删除登录活动来清除后堆栈。 And set null value to setter in Application class. 并在Application类中将空值设置为setter。

Feel free to share any concern regarding this. 随时分享对此的任何关注。 Thank you. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM