2017-09-15 61 views
0

我需要运行一个活动,但清除所有的堆栈,即使是我运行一个新堆栈的活动。如何从Acrtivities中清除背堆栈(当前任务)

这里是一个例子。

A->B 

活动A开始活动B

开始活动B.

Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK 
Intent.FLAG_ACTIVITY_NO_HISTORY 

时但是,当活动B开始我仍然可以看到活动我曾尝试使用以下标志A在任务中。 使用以下命令

adb shell dumpsys activity | grep -i run 

,得到了以下结果

Running activities (most recent first): 
    Run #0: ActivityRecord{5296b78c u0 com.android.launcher/com.android.launcher2.Launcher t1} 
Running activities (most recent first): 
    Run #2: ActivityRecord{528a3310 u0 com.test.app/com.test.app.B t19} 
    Run #1: ActivityRecord{52bb7a34 u0 com.test.app/com.test.app.A t19} 
    Run #0: ActivityRecord{52c7ed5c u0 com.android.documentsui/.DocumentsActivity t11} 
ACTIVITY MANAGER RUNNING PROCESSES (dumpsys activity processes) 
User #0: mState=RUNNING 

正如你可以看到一个活动还在这里。是否有可能清除后端堆栈?

+0

你完成你的酶活性的同时,对活动B移动? –

回答

0

尝试这样,

Intent intent = new Intent(this, NewActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    startActivity(intent); 
    finish();//you want to close your activity,just call finish 
+0

请阅读我的问题,我已经在使用此标志 – bxfvgekd

+0

你使用完成()吗? – Rgv

0

试试这个

Intent intent = new Intent(this, ActivityA.class); 
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK); 
    startActivity(intent); 

这里IntentCompat在Android的支持库添加类。

0

如果活动B逼人退不应该导航回活动A可以将其设置在AndroidManifest.xml

<activity 
     android:name=".A" 
     android:noHistory="true"> 
</activity>