如何从活动X启动活动Y,从堆栈中删除X,并且Y在新堆栈中

时间:2015-01-27 19:05:26

标签: android android-activity

I have an application with two activities.
A and B

显示不同活动的清单xml。

    <activity
        android:name=".A"
        android:launchMode="singleInstance"
        android:excludeFromRecents="true"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".B"
        android:label="@string/title_activity_money_manager_home"
        android:screenOrientation="portrait">
    </activity>

活动的启动方法如下:
     活动A - &gt;活动B [从B发起]

Intent i = new Intent(this,B.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(i);

After that ,

I want 

i) **A** need not be seen in Recents 
ii) From **B** , If i press back key , **A** need not be shown . i.e A should be shown only once like a splash screen of an application
iii)The Activity **B** need to be in **new stack** and it need to be root of application


Please help me out ..

1 个答案:

答案 0 :(得分:0)

在startActivity之后调用完成

Intent i = new Intent(this,B.class);
startActivity(i);
finish();