5

Situation

Activity A -> Activity B -> Activity C

When Activity C starts I'd like C becomes the root Activity, while A and B finish.

How can I achieve this?

UDPATE

I am on Level 10, so I can't use CLEAR_TASK flag that is for level 11 and superior.strong text

Noodles
  • 3,263
  • 4
  • 19
  • 22
  • You want A and B only to finish med C is launched? Otherwise you could call finish() before you start a new activity. – Carnal Oct 24 '12 at 10:11
  • Take a look at this similar [post][1] [1]: http://stackoverflow.com/questions/5979171/clear-all-activities-in-a-task – Damien Praca Oct 24 '12 at 10:12
  • @Carnal: yes I know but I have to call finish on both A and B only just starts C – Noodles Oct 24 '12 at 10:20
  • @DamienPraca sorry but CLEAR_TASK is only for Level >= 11 I am on Level 10 – Noodles Oct 24 '12 at 10:20
  • Well, I don't know if this is a good idea. But you could create a List of Activities, and in A and B you add yourself to this list, and in C, you take out this two activities and call finish() on them. Just a thought! – Carnal Oct 24 '12 at 10:24

4 Answers4

0

Set the following line the entry of activity C in the manifest

android:clearTaskOnLaunch="true"

http://developer.android.com/guide/topics/manifest/activity-element.html#clear

Ion Aalbers
  • 7,830
  • 3
  • 37
  • 50
0

put a flag into your launching intent:

FLAG_ACTIVITY_CLEAR_TASK

example: Intent launchC = new Intent(getApplicacionContext(),nameC.class);

launchC.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

basiclly same that previous answer, but previous method obligates clear task every time that you launch C, but with the flag you can have a different control. Cheers

BackToBasics
  • 152
  • 1
  • 1
  • 10
0

UPDATE FOR SOLUTION

I solve it using startActivityForResult and dispatching back a result.

Noodles
  • 3,263
  • 4
  • 19
  • 22
-1

after calling

startactivity() method call this.finish();

on A, then B

hope this fulfill your requirement

Fawad
  • 137
  • 1
  • 9
  • I have to finish A and B only when C starts, I don't want to call finish() when I start B from A. – Noodles Oct 24 '12 at 10:22
  • did u mean u have to end A and B , which are in pause state Simultaneously when C is Running? – Fawad Oct 24 '12 at 10:25