2017-09-15 59 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>