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?

Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
  • Simply call `finish()` in B so that it self terminates after it starts A. – Squonk Sep 10 '12 at 20:17
  • after the startActivity(A) on B's code? – Ofek Ron Sep 10 '12 at 20:18
  • I think the [solution to a very, very recent question](http://stackoverflow.com/a/12358563/1438733) 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 Sep 10 '12 at 20:18
  • @OfekRon : Yes, exactly. – Squonk Sep 10 '12 at 20:18
  • @Squonk please put it on answer, it seem to work, ill be testing it and accept your answer if no other issue comes up, Thanks! – Ofek Ron Sep 10 '12 at 20:21
  • @Eric that should work too, i wonder which solution is better... – Ofek Ron Sep 10 '12 at 20:22
  • @Eric is it possible to set Activvity's noHistory attr on Manifest XML? if so how? – Ofek Ron Sep 10 '12 at 20:26
  • @Squonk what do you think of the alternative? it seem more appropriate then calling the finish() method since it lets the OS do it in its own way, dont you think? – Ofek Ron Sep 10 '12 at 20:28
  • 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 Sep 10 '12 at 22:56

1 Answers1

1

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

startActivity(new Intent(this, ActivityA.class));
finish();
Squonk
  • 48,735
  • 19
  • 103
  • 135