完成之前的所有活动 [英] Finish all previous activities

查看:26
本文介绍了完成之前的所有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有以下流程屏幕:

My application has the following flow screens :

首页->屏幕1->屏幕2->屏幕3->屏幕4->屏幕5

现在我在每个屏幕上都有一个通用的log out按钮

Now I have a common log out button in each screens

(Home/screen 1/screen 2/screen 3/screen 4/screen 5)

我希望当用户单击注销按钮(从任何屏幕)时,所有屏幕都将完成并打开一个新屏幕 Log in .

I want that when user clicks on the log out button(from any screen), all the screens will be finished and a new screen Log in will open .

我已经尝试了几乎所有 FLAG_ACTIVITY 来实现这一点.我也在stackoverflow中查看了一些答案,但无法解决问题.我的应用程序在 Android 1.6 上,因此无法使用 FLAG_ACTIVITY_CLEAR_TASK

I have tried nearly all FLAG_ACTIVITY to achieve this. I also go through some answers in stackoverflow, but not being able to solve the problem. My application is on Android 1.6 so not being able to use FLAG_ACTIVITY_CLEAR_TASK

有什么办法可以解决这个问题吗?

Is there any way to solve the issue ?

推荐答案

使用:

Intent intent = new Intent(getApplicationContext(), Home.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

这将清除主页上的所有活动.

This will clear all the activities on top of home.

假设您在用户登录并创建主页时完成登录屏幕,然后在该屏幕之上创建从 1 到 5 的所有屏幕.我发布的代码将使您返回主屏幕完成所有其他活动.您可以在意图中添加额外内容,并在主屏幕活动中阅读并完成它(也许从那里再次启动登录屏幕之类的).

Assuming you are finishing the login screen when the user logs in and home is created and afterwards all the screens from 1 to 5 on top of that one. The code i posted will return you to home screen finishing all the other activites. You can add an extra in the intent and read that in the home screen activity and finish it also (maybe launch login screen again from there or something).

我不确定,但您也可以尝试使用此标志登录.我不知道在这种情况下将如何订购活动.所以不知道它是否会清除您正在使用的屏幕下方的那些,包括您当前所在的那个,但它绝对是要走的路.

I am not sure but you can also try going to login with this flag. I don't know how the activities will be ordered in that case. So don't know if it will clear the ones below the screen you are on including the one you are currently on but its definitely the way to go.

希望这会有所帮助.

这篇关于完成之前的所有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆