-1

I have a main activity (A) that starts a new activity (B) that calls a third activity (C). When pressing a button on activity C, i would like to return to activity A and also close activity B.

Schema:

A -(opens)> B -(opens)> C

When pressing a button on activity C I only want to have activity A, so I need to kill B and C.

On Activity C i can just call finish().

What to do with activity B?

Bugdr0id
  • 2,962
  • 6
  • 35
  • 59

2 Answers2

5

When you open activity C from Activity B call finish() on Activity B so that when you call finish() on Activity C it will go to Activity A but not B because B is not the stack anymore.

OR

Call Activity A from Activity C with the below intent flags.

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

These flags will clear the entire Activity stack

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Avinash4551
  • 220
  • 1
  • 9
  • 1. What if user wants to change some details filled in Activity B and for that presses back button from Activity C? 2. What if there are other activities in queue before Activity A (e.g. X -> Y -> A -> B -> C) and user just want finish activities B and C? – Chintan Shah May 03 '17 at 06:26
0

So you want to finish an activity from another activity, check these two answers

How to finish an activity from other activity

What is the right way to clear background activity/activites from stack ?

Community
  • 1
  • 1
A.J
  • 726
  • 1
  • 7
  • 19