如何在离开Android活动时将其杀死,以使其无法通过“后退"按钮进行访问? [英] How to kill an Android activity when leaving it so that it cannot be accessed from the back button?

查看:70
本文介绍了如何在离开Android活动时将其杀死,以使其无法通过“后退"按钮进行访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定的Android活动中,我想在某个时候为用户启动一个新活动.当他们离开第一个活动并到达第二个活动时,第一个活动已过时,我想将其完全删除,以使其无法从后退"按钮再次访问.

In an given Android activity, I would like to start a new activity for the user at some point. Once they leave the first activity and arrive at the second, the first activity is stale and I want to remove it completely so it can not be accessed again from the back button.

如何做到这一点的最佳方法?用户启动新活动后,如何立即杀死或销毁该活动?

How is the best way to accomplish this? How do I kill or destroy this activity immediately after the user has launched the new activity?

推荐答案

您只需要致电finish()

Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
finish();

这篇关于如何在离开Android活动时将其杀死,以使其无法通过“后退"按钮进行访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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