天天看點

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK黑屏問題

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK用來啟動一個activity,把與該activity相關的activity棧清空,就是保證啟動後的activity之後沒有其它activity(不同的taskAffinity除外)

在intent加入這個flag有個問題啟動的activity有一段黑屏時間,原因可能因為

this flag will cause any existing task that would be associated with the activity to be cleared before the activity is started.
           

解決這個,可以在被啟動的activity的主題中設定windowDisablePreview屬性為true,android為了達到快速啟動的目的,在應用還在背景加載的時候就調用了啟動視窗,而windowDisablePreview設定true則把這一特性禁用,在activity加載完成之後在顯示視窗。