Reputation: 9814
I have read this article: http://developer.android.com/guide/components/tasks-and-back-stack.html
If I read it correctly it says you can create a new task with a new activity while the old task still has a backstack. They are also talking about returning to an old taks. However I did not find how to implement this.
What I want:
I have a navigation drawer. I want to click an item. When back is pressed it goes back to the root. But if you click another item, the backstack is saved in the current task. Then a new backstack is created in this other item. When clicking the first item again I want to go to the top of the backstack, so continuing where you were.
Example:
Is this possible?
NOTE: I work with activities, it is a large app and activities are easier to maintain.
Upvotes: 2
Views: 833
Reputation: 30611
The purpose of the NavigationDrawer
is to simplify navigation that would otherwise be complex and tedious to manage, both for the user and programmer. What you should do is, whenever you start a new Activity
from the root Activity
(A1
), you should start it like this:
Intent intent = new Intent(this, A2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent);
This will ensure that A1
is ALWAYS the root of the backstack.
I don't know what specific reasons you have for wanting the behavior you describe, but I would consider what I have described above to be appropriate, graceful handling of the backstack.In any case, it would be extremely challenging to implement the behavior you are asking for.
Upvotes: 1