0

Let us say I have 4 activities, A,B,C and D. Activity A starts B, B starts C using Intent. A button click in Activity C starts D. Clicking back button or closing Activity D should take me to Activity A. I have achieved this by starting Activity A with FLAG_ACTIVITY_CLEAR_TOP and FLAG_ACTIVITY_SINGLE_TOP flags from Activity C. onNewIntent in Activity A, I started Activity D so that clicking back or closing D will take to A.

I use entry and exit animation while starting and exiting the activities. For the above scenario, after the exit animation ends in Activity C I start Activity A. The problem here is since I start the activity after the animation I see the back stack ie, Activity B when Activity C animates down. I don't want to see Activity B in the back stack rather see Activity A. Not sure how to achieve this.

Is there any way to clear a part of the stack and then start a new activity?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

0

I believe you are asking if you can run two activities at the same time. You can call finish() on your current activity, however that activity will be done and completed then.

If you want to open another view without stopping your current view / activity, you should look into Fragments. They can run parallel and won't have this issue.

In case I misunderstood apologies.

jetspiking
  • 304
  • 1
  • 5
0

Place the FLAG_ACTIVITY_CLEAR_TOP after the startActivity(intent); like this:

startActivity(i, ActivityOptions.makeSceneTransitionAnimation(this).toBundle());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Ole Pannier
  • 3,208
  • 9
  • 22
  • 33