如何在android中一次完成多个活动? [英] How to finish multiple activities at once in android?

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

问题描述

我的活动流程是这样的活动 C 和 D.我该怎么做?

I have my Activity flows like this ACTIVITY A -> ACTIVITY B -> ACTIVITY C -> ACTIVITY D. When the user is on Activity D and click a button called exit, the application should go back to Activity B and finish the Activities C and D. How can I do that?

注意:ACTIVITY B 和 ACTIVITY D 是同一个类但是不同的实例

NOTE : ACTIVITY B and ACTIVITY D are the same class but different instance

推荐答案

AndroidManifest.xml 中,设置 android:noHistorytrueActivity B、C 和 D. 将其设置为 Activity A 的 false(实际上,默认为 false).

In AndroidManifest.xml, set android:noHistory as true for Activity B, C and D. set it as false for Activity A (actually, the default is false).

演示:

<activity android:name=".xx.xx.ActivityA" 
    android:noHistory="false"
    android:screenOrientation="nosensor">
</activity>

<activity android:name=".xx.xx.ActivityB" 
    android:noHistory="true"
    android:screenOrientation="nosensor">
</activity>        

<activity android:name=".xx.xx.ActivityC" 
    android:noHistory="true"
    android:screenOrientation="nosensor">
</activity>

<activity android:name=".xx.xx.ActivityD" 
    android:noHistory="true"
    android:screenOrientation="nosensor">
</activity>

对于退出Button:

exitBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(getApplicationContext(),ActivityB.class);
        startActivity(intent);
        finish();
    }
});

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

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