安卓应用第一次启动的时候,会有点慢,而且在启动之间有一个白屏的过程。
记录几个优化Activity启动时间和闪白屏的方法:
一、release版本启动时间快
使用Android Studio用release发布apk。测试release版本Activity启动时间比Debug版本快1s左右。
优化第一次启动时间。
二、解决闪白屏问题
在style.xml中加入:
android:windowIsTranslucent" 和 android:windowNoTitle的配置,目的是在Activity启动之前,窗口是透明的不会白屏。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
//add
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>