Android的Intent.FLAG_ACTIVITY_CLEAR_TOP無效


轉載:http://blog.csdn.net/u011361576/article/details/48626237

 

今天寫代碼遇到了一個問題:

當 B - A - B 跳轉的時候,使用Intent的FLAG_ACTIVITY_CLEAR_TOP會讓第一個B和第二個A,destory掉,但是當B - A - C跳轉的時候不會調用B和A的destory。

查看API文檔才發現原因,所以這里記錄一下避免下次忘記了:

 

public static final int FLAG_ACTIVITY_CLEAR_TOP

Added in  API level 1

If set, and the activity being launched is already running in the current task, then instead of launching a new instance of that activity, all of the other activities on top of it will be closed and this Intent will be delivered to the (now on top) old activity as a new Intent.

 

如果設置這個屬性,是當要啟動的Activity已經存在當前Task中,才會在啟動的時候銷毀其他的Activity。

所以上面當A跳C的時候不滿足此條件。

 

當然如果想實現這個效果可以使用:

it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);

 

不過此方法要求最低API為11


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM