Search code examples
androidandroid-activityactivity-finish

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.

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. After an animation, the activity's background becomes opaque. While this is happening, the homescreen is showing because activity A finishes quickly.

Thank you in advance.


Solution

  • Here is one not-so-straightforward approach at the top of my head. You can use something called LocalBroadcast Manager. It would be like a message from Activity B to Activity A saying that 'Hey, I've finished loading the animation. 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. Then when on your activity B the animation finishes, you can send a Local Broadcast message saying "I don't need you"(not literally). This will be received by receiver in Activity A, where you can finish it.

    See how to use LocalBroadcastManager? for how to implement it easily. Hope it helps you.