문제

In my android application I have the simple following scenario:

Activity A calls Activity B so the Activity Stack is (from top to bottom):

B - A

Now I want call A from B, finishing B activity.

If I simple use finish() the activity B will be finished, but A remains in his previous state. Instead I want have A in the initial state. So I want to finish the previous instance of activity A and create a new instante of it (removing B from stack)

How can I perform this task?

도움이 되었습니까?

해결책

Calling startActvitity A in B with a flag intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

For example, consider a task consisting of the activities: A, B, C, D. If D calls startActivity() with an Intent that resolves to the component of activity B, then C and D will be finished and B receive the given Intent, resulting in the stack now being: A, B.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top