3

In my app i am starting activities one after the another and not finishing any activity before calling another. But when user presses logout button then i want to finish all the activities from the stack and start login activity.

Activity Login(finish & call) --> Activity B --> Activity C--> Activity D --> Logout -->Acitivity Login.

If user presses back key on login activity then he returns to Activity C in my case... but i want to avoid that.

4

2 回答 2

7

您应该做的是调用Login活动,并清除堆栈中它上面的所有活动。

Intent intent = new Intent(this, Login.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

这将标记它以创建一个新的登录活动,而不仅仅是恢复之前的登录活动。并清除它上面的所有活动。(B、C、D)。

于 2012-10-20T18:05:45.793 回答
0

我不知道它是否会有所帮助,但您可以尝试将以下标签添加到清单的声明活动(B、C、D)中:

android:noHistory='true'

当用户离开它并且它不再在屏幕上可见时,该活动应该从活动堆栈中删除并完成(调用它的完成()方法)

看看这里

于 2012-10-20T18:09:40.817 回答