I have two activities, one is a list for item, the other one is the edit view for the item. When user clicks the item in the first view, the second edit view will show.
In android the stack based mechanism, if I do this the behavior is w开发者_开发问答eird.
List view -> click -> edit view -> save -> list view -> click -> edit ->... it's a loop.
If I edit and save the item several times the stack will be full of list view & edit view...
Now the user wants to press back key to exit the program, by stack based activity manager, the user will meet up many times of the two activities.
What's the recommend way to resolve this issue?
Pardon me if I'm wrong but I think you handle the Edit->List switching with a startActivity().
I think you should just finish()
your activity when you handle save (letting activity stack go back to List)
For your any one of the activity as per your requirement set the following attribute in your project manifest file
android:noHistory="true"
so that activity will not be kept on stack and chain will break.
From ListView actiivty call EditView activity by startActivityForResult()
. and after save the EditView just finish()
the EditView activity.
and in Manifest file just put android:noHistory="true"
.
EDIT:
android:noHistory
Whether or not the activity should be removed from the activity stack and finished (its finish() method called) when the user navigates away from it and it's no longer visible on screen — "true" if it should be finished, and "false" if not. The default value is "false".
A value of "true" means that the activity will not leave a historical trace. It will not remain in the activity stack for the task, so the user will not be able to return to it.
This attribute was introduced in API Level 3.
You Can also write this code for back to activity if you want to move back five stack back then put this line code
moveTaskToBack(true);
moveTaskToBack(true);
moveTaskToBack(true);
moveTaskToBack(true);
moveTaskToBack(true);
精彩评论