完成android中的活动? [英] Finish an activity in android?

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

问题描述

我有一些活动.

Home Activity -> Activity 1 -> Activity 2 -> Activity 3 -> HomeActivity
                 finish();      finish();     finish();

Home Activity -> Activity 1 -> Activity 2 -> Activity 3 -> Activity 4 -> HomeActivity
                 finish();      finish();     finish();     finish();

现在,当我进入HomeActivity的最后一步时,如果按后退"按钮,它将再次带我进入家庭活动.

So now when I am on the final step that is on the HomeActivity if I press back button it again takes me on to the home activity.

如何完成家庭活动而不干扰整个过程?任何帮助表示赞赏.

How do I finish the home activity without disturbing the whole process? Any help appreciated.

推荐答案

将此标志与您在每次活动中的意图结合使用

use this flag with your intent in each activity

i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

这将不会再次启动家庭活动.它将使用您的家庭活动的先前实例并将其显示在顶部.

This will not launch home activity again . It will use the previous instance of you Home Activity and bring it to top.

with CLEAR_TOP如果正在启动的活动已经在当前任务中运行,那么与其启动该活动的新实例,不如关闭该活动之上的所有其他活动,并将此Intent传递给(现在最重要)旧活动作为新的Intent.

with CLEAR_TOP If 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.

您可以参考此链接以获得有关标志的更多信息.

You can refer this Link to get more idea about flags.

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

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