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

启动过慢

在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的图片显示不一致。





评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值