除了一个明确的Andr​​oid /结束previous活动 [英] Android clear / finish previous activities except one

查看:130
本文介绍了除了一个明确的Andr​​oid /结束previous活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的,我有以下路径:

In android I have the following path:

活动1 - >活动2 - >活动3 - > ...活动N - > preSS按钮...

Activity 1 -> Activity 2 -> Activity 3 -> ... Activity N -> press button ...

当pressed的按钮,我想清楚了/完成从活动2中的所有活动,直到N和然后去Acitivy X.换句话说,我要完成所有的活动下来到最初的一,然后移动到另一个。

When the button is pressed I want to Clear/Finish ALL activities from Activity 2 until N and then go to Acitivy X. In other words I want to finish all activities down to the initial One and then move to another.

如果我使用的标志:

CLEAR_TOP,CLEAR_TASK,NEW_TASK等

CLEAR_TOP, CLEAR_TASK, NEW_TASK etc

theoritically将完成所有previous活动与最初之一。有没有什么办法,以保持初始的人活着,并移动到活动X'

theoritically it would finish ALL previous activities with the initial one. Is there any way to keep the initial one alive and move to activity X?

推荐答案

如果您已经访问过actitvity,并没有叫结束(); 在离开它,然后 做到这一点

if you have already visited a actitvity and have not called finish(); on leaving it then do this

  finish();
                Intent mIntent = new Intent(Create_Your_Pizza.this, MainActivity.class);
                mIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);;

                mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(mIntent);

这篇关于除了一个明确的Andr​​oid /结束previous活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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