您的位置:首页 > 移动开发

解决APP启动缓慢以及黑屏问题

2015-11-18 18:15 519 查看

启动过慢

在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>




AndroidManifest.xml文件:
<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的图片显示不一致。

更多链接:http://www.jb51.net/article/40111.htm
https://github.com/android-cn/android-discuss/issues/117
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息