1

Well i have 2 activities, say A and B, user zipping between them like crazy A then going to B then A etc, now i dont want the normal behavior of zipping back to home through all those "layers" of A and B.

I want that if the user is in A it will go back to Home, if he is in B he will go back to A, and i want to do that as traditional and system friendly as possible - which means that i dont want workarounds that would fill my Activity stack nor do i want to start activities on new tasks.

i have tried using android:clearTaskOnLaunch="true" on activity A, and as it is documented it seems like the best thing to do, but it doesnt provide the documented behavior - it is behaving the same as it did without it...

what do you suggest?

9
  • Simply call finish() in B so that it self terminates after it starts A.
    – Squonk
    Commented Sep 10, 2012 at 20:17
  • after the startActivity(A) on B's code?
    – Ofek Ron
    Commented Sep 10, 2012 at 20:18
  • I think the solution to a very, very recent question will apply here and is probably the best solution. If B is started from A using this flag, then A is started again, "back" will not return to B.
    – Cat
    Commented Sep 10, 2012 at 20:18
  • @OfekRon : Yes, exactly.
    – Squonk
    Commented Sep 10, 2012 at 20:18
  • 1
    @OfekRon : It really depends on the behaviour you need. Calling finish() is perfectly acceptable if the Activity starting another Activity will no longer be needed and by calling it, the Activity will go through all of its life-cycle stages. Basically, onPause(), onStop() and onDestroy() will be called and the Activity will be cleaned up normally.
    – Squonk
    Commented Sep 10, 2012 at 22:56

1 Answer 1

1

If you use finish() in B after it starts A then B will self terminate...

startActivity(new Intent(this, ActivityA.class));
finish();

Not the answer you're looking for? Browse other questions tagged or ask your own question.