I have three activities: A, B, C.
Activity A can start B or C.
When A starts C i can return to A just have pressed back button. But i want “return” to B and then to A (with second press of back button).
I tried to use TaskBackStack in this way:
final TaskStackBuilder builder = TaskStackBuilder.create(this)
.addParentStack(this)
.addNextIntent(new Intent(this, B.class))
.addNextIntent(new Intent(this, C.class));
builder.startActivities();
But its not working… Can anyone help me?
Sorry for my English and thanks in advance
Before try to answer you question I have some comments about your approach to navigate between your activitys. In general, this approach is not a good idea, because doing that, you are not following the Android Navigation Pattern, and this can make your application not user friendly, since most Android Application use the Navigation Pattern.
The Android Navigation Pattern says:
However, there is another possiblite to Navigate in your application using The Android Pattern, but I believe that is not a solution for your problem. You can take a look at Up Navigation
To finalize, I have a relevant comment about solution that uses override the OnBackPressed() to Start a new Activity. You should really avoid that, because using it, you will can make crazy your chronologic navigation. Because when you create an activity inside the OnBackPressed, you are always putting a new activity on Android Stack, so there are two problems here: