启动过慢
在app启动的时候,如果发现应用启动过慢,有可能是下面的情况引起的:
1、依赖了过多的lib
2、app引用的资源导致加载时间过长
3、在启动页面的onCreate和onResume执行了耗时比较长的事务
启动过慢-->导致黑屏
闪黑屏的原因主要是我们启动Activity的时候,需要跑完onCreate和onResume才会显示界面,但我们可以通过一下两个办法解决这个问题:
把起始页面的图片作为窗口的背景图:::
styles.xml文件:
<pre name="code" class="java">//1、设置背景Theme
<style name="Theme.AppStartLoad" parent="android:Theme">
<item name="android:windowBackground">@drawable/ipod_bg</item>
<item name="android:windowNoTitle">true</item>
</style>
//2、设置透明Theme
<style name="Theme.AppStartLoadTranslucent" parent="android:Theme.NoTitleBar.Fullscreen">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
<activity
android:name=".StartActivity"
<!-- 使用上面定义的样式 mythou-->
android:theme="@style/Theme.AppStartLoad"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
注意:上面的自定义style,需要使用android:Theme.NoTitleBar.Fullscreen这个主题,否者起始页面中的图片会与android:windowBackground的图片显示不一致。