美文网首页
Android性能优化-App启动优化

Android性能优化-App启动优化

作者: 河马过河 | 来源:发表于2018-09-13 19:38 被阅读34次

一、App启动优化

问题如下:
1、App启动白屏、或者黑屏
2、App启动时间长

二、解决方法1

通常的解决办法都是给Activity设置一个透明背景的主题

<style name="SplashTheme" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsTranslucent">true</item>
</style>

结果如下:

优点:确实没有白屏和黑屏了
缺点:1、给SplashActivity设置后,用户点击我们APP图标后,需要等待2秒左右的时候才会显示contentView。造成了APP启动速度慢的假象,其实Activity已经启动了,只是background是透明的,这时候你点击桌面的其他地方是无效的。这样就和Google的初衷背道而驰了
2、给其他Activity设置后,会导致通过overridePendingTransition设置的启动关闭Activity的动画无效。需要在style中重新写如下几个动画:

<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowAnimationStyle">@style/Animation.Activity.Translucent.Style</item>
<item name="android:windowFullscreen">true...
<item name="android:windowIsTranslucent">true...
</style>

<style name="Animation.Activity.Style" parent="@android:style/Animation.Activity">
<item name="android:activityOpenEnterAnimation">...
<item name="android:activityOpenExitAnimation">...
<item name="android:activityCloseEnterAnimation">...
<item name="android:activityCloseExitAnimation">...
</style>

<style name="Animation.Activity.Translucent.Style" parent="@android:style/Animation.Translucent"> 
<item name="android:windowEnterAnimation">...
<item name="android:windowExitAnimation">...
</style>  

3、Activity之间的跳转可能偶尔会看到桌面一闪而过(如果SplashActivity和其他Activity都设置了透明)

三、解决方式2

给主题设置Window背景图片

<style name="SplashTheme" parent="AppBaseTheme">
    <!-- 欢迎页背景引用刚才写好的 -->
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowFullscreen">true</item>
    <!-- <item name="android:windowIsTranslucent">true</item> --> <!-- 透明背景不要了 -->
</style>

结果如下:

优点:确实解决了白屏、黑屏问题
缺点:华为手机HUAWEI MT7-TL00出现bug-图片先显示了一次模糊的、带黑圈的圆角图片,再显示了一次全屏清晰图片

四、解决方式3

给主题设置Window背景图片

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 背景颜色 -->
    <item android:drawable="@color/white" />

    <item>
        <!-- 图片 -->
        <bitmap
            android:gravity="center"
            android:src="@drawable/wel_page" />
    </item>
</layer-list>
<style name="SplashTheme" parent="AppBaseTheme">
    <!-- 欢迎页背景引用刚才写好的 -->
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowFullscreen">true</item>
    <!-- <item name="android:windowIsTranslucent">true</item> --> <!-- 透明背景不要了 -->
</style>

优点:确实解决了白屏、黑屏问题
缺点:华为手机HUAWEI MT7-TL00出现bug-图片确实只显示了一次图片,但是图片确实被截取后的图片,并没有显示全图

五、最终解决方式

在方法4的基础上修改

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="fill"
            android:src="@drawable/bg_splash" />
    </item>
</layer-list>
<style name="SplashTheme" parent="AppBaseTheme">
    <!-- 欢迎页背景引用刚才写好的 -->
    <item name="android:windowBackground">@drawable/splash</item>
    <item name="android:windowFullscreen">true</item>
    <!-- <item name="android:windowIsTranslucent">true</item> --> <!-- 透明背景不要了 -->
</style>

参考:
https://blog.csdn.net/yanzhenjie1003/article/details/52201896:严振杰

河马过河微信公众号.jpg

相关文章

  • Android系统原理

    Android性能优化(一)App启动原理分析及启动时间优化 - CSDN博客 Android性能优化(二)布局渲...

  • Android性能优化之启动速度优化

    Android性能优化之启动速度优化 Android app 启动速度优化,首先谈谈为什么会走到优化这一步,如果一...

  • Android 性能优化

    app性能优化 android优化分为: 内存优化 UI优化 电量优化 apk瘦身优化 启动优化 下面通过各种百度...

  • 收集_性能优化

    Android性能优化(一)之启动加速35%Android性能优化(二)之布局优化面面观Android性能优化(三...

  • Android性能优化--内存优化

    转载自:Android性能优化--内存优化 上一篇文章关于Android性能优化--启动优化探讨了启动优化相关的知...

  • Android性能优化之路

    Android性能优化目录 1 Android性能优化之内存泄漏2 Android性能优化之启动速度3 Andro...

  • iOS 性能优化三

    主要讲解APP冷启动的优化 iOS 性能优化一iOS 性能优化二iOS 性能优化三 1. APP 启动的分类 冷...

  • Android性能优化[执行时间优化]

    Android性能优化[启动优化] 在了解了启动优化后,Application会做一些初始化的工作,但不要在App...

  • MS(4):Android之性能优化篇

    六、性能及优化 1、App优化之性能分析工具 Android App优化之性能分析工具 2、ListView优化 ...

  • Android优化六:性能优化

    Android优化一:提纲Android优化二:性能检测Android优化三:内存优化Android优化四:App...

网友评论

      本文标题:Android性能优化-App启动优化

      本文链接:https://www.haomeiwen.com/subject/sajggftx.html