简体   繁体   English

在开始新活动之后(延迟)完成活动

[英]Finish activity AFTER (delay) starting a new one

Not sure how to do this: 不确定如何执行此操作:

Current activity is: A

I want to start activity: B

But I want that activity B's UI should load completely before Activity A is finished. 但是我希望活动B的UI应该在活动A完成之前完全加载。

What I need: 我需要的:

Current activity is: A

Start new activity: B

Activity B loads completely

Activity A finishes

I need this because activity B's UI is translucent when it starts. 我需要这样做,因为活动B的UI在启动时是半透明的。 After an animation, the activity's background becomes opaque. 动画后,活动的背景变得不透明。 While this is happening, the homescreen is showing because activity A finishes quickly. 在这种情况下,由于活动A快速完成,因此显示了主屏幕。

Thank you in advance. 先感谢您。

Here is one not-so-straightforward approach at the top of my head. 这是我脑海中一种不太直接的方法。 You can use something called LocalBroadcast Manager . 您可以使用称为LocalBroadcast Manager的名称 It would be like a message from Activity B to Activity A saying that 'Hey, I've finished loading the animation. 就像是从活动B到活动A的消息,说:“嘿,我已经完成了动画的加载。 Now I don't need you!". 现在我不需要你了!”。

So, before starting a new activity your activity A can start listening for this local broadcast and register a receiver. 因此,在开始新活动之前,您的活动A可以开始侦听此本地广播并注册接收者。 Then when on your activity B the animation finishes, you can send a Local Broadcast message saying "I don't need you"(not literally). 然后,在活动B上完成动画后,您可以发送一条本地广播消息,说“我不需要你”(不是字面上的意思)。 This will be received by receiver in Activity A, where you can finish it. 这将由活动A中的接收者接收,您可以在其中完成它。

See how to use LocalBroadcastManager? 看看如何使用LocalBroadcastManager? for how to implement it easily. 有关如何轻松实现它。 Hope it helps you. 希望对您有帮助。

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

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