在自己的項目中。我須要使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK來開始新的activity同一時候移除之前全部的activity。
我使用這個intent flag的代碼例如以下:
Intent intent = new Intent(Gerenxinxi.this, MainPart.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); finish()
可是當運行這段代碼的時候,我發現會有一段黑屏的時間段(非常短。可是能非常明顯感覺出來)。
我試着把intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);這行代碼去掉,發現黑屏就不見了。為了測試,使用其它的flag。如FLAG_ACTIVITY_CLEAR_TOP等均沒有發生黑屏的情況,可是依據需求我又必需要使用Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK。后來經過自己的查找和測試,發現通過以下的方法能夠去掉黑屏。
假設是像上面的代碼那樣所展現的是從Gerenxinxi這個activity跳轉到MainPart。那么我們在AndroidManifest里的mainpart的配置應該是這種:
<activity android:name="com.ci123.jiayuanbao.school.MainPart" android:screenOrientation="portrait" android:theme="@style/AppTheme_yu" > </activity>
同一時候,在style里我們要配置style:
<style name="AppTheme_yu" parent="@android:style/Theme.Light"> <item name="android:windowNoTitle">true</item> <item name="android:animationDuration">0</item> <item name="android:windowDisablePreview">true</item> </style>主要是<item name="android:windowDisablePreview">true</item>。能夠去掉之前所出現的黑屏。
這是我在網上問的問題。別人回復的鏈接:http://stackoverflow.com/questions/31264157/how-to-avoid-black-screen-when-intent-flag-activity-new-task-intent-flag-activ