app启动优化,解决空白页或者卡顿太久

废话不多说,先讲下原因,application的待执行的指令过多,启动页启动前会先执行application的相关方法。
好了,原因说完了,至于怎么优化,那就自己去度吧,我这里说的是启动app时尽快出现启动页。
比如启动页是GuideActivity


<activity
    android:name=".GuideActivity"
    android:screenOrientation="portrait"
    android:theme="@style/SplashTheme">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

 



重点是设置theme
style代码:
<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>
<!-- Base application theme. -->
<style name="SplashTheme" parent="AppTheme.NoActionBar">
    <item name="android:windowBackground">@drawable/logo_splash</item>
</style>

 



好了,结束,so easy 要优化性能还是改application比较好,这个方法是用在优化后还慢的处理方法
需要注意的是,这里设置了theme后,可以不需要再设置
setContentView(R.layout.activity_guid);
这样会导致重复绘制,造成没必要的资源浪费。


posted @ 2018-02-01 15:09  童话二分之一  阅读(359)  评论(0编辑  收藏  举报