android - 安卓应用冷启动如何避免开机白屏?
黄舟
黄舟 2017-04-18 09:16:42
0
5
712

我一直以为只要在 application的theme下设置background就好了,(同类型解决方法还有设置为透明)
但是今天在实际测试中发现,
在oppo m37a 上是有效果的(api 22)
但是在红米4 上发现是没有效果的!(api23)

我尝试打开红米4上多款应用发现:

  • 瞬间打开且没有白屏

    1. 高德地图

    2. 掘金

    3. segmentfault

    4. 手机淘宝

    5. 印象笔记

    6. 等。。。

  • 有白屏

    1. 知乎日报

    2. 扇贝单词

    3. 人民日报

    4. 摩拜单车

  • 没有白屏,但是点击icon 会延迟一会才打开

    1. 简书

    2. UC浏览器

    3. 支付宝

    如果是白屏或者是“延迟打开”,我觉得可以办到

那要怎样才能做到segmentfault ,手机淘宝这样呢?

启动第一个activity,这个activity 只是为了作为背景显示,把一些初始化的工作放到第2个activity中?
这样的话做法好奇怪啊?应该有什么更直接的方案吧?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(5)
巴扎黑

To set up background也应该是windowBackground, you don’t need two activities to implement it. If it reaches this point, it is very likely that your application or main activity is doing too much main thread work.

左手右手慢动作

Set startup to transparent and add the following code to the theme file

<item name="android:windowDisablePreview">true</item>
PHPzhong

<style name="welcomeTheme" parent="AppTheme">

    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowBackground">@android:color/transparent</item>
</style>

Set the theme and then quote it here
<activity

        android:name=".Activity.LoadingActivity"
        android:theme="@style/welcomeTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

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

If you have to do too much work in the application, I have a simple method, which can be started by process through multi-process mode. The secondary process is responsible for starting a screensaver interface when the main process starts and initializes. When the main process completes the initialization, it is sent to the secondary process. Exit, and the main process interface starts. This avoids the problem of too slow initial startup caused by excessive initialization of the application.

左手右手慢动作

First clarify why the white screen is white, and then modify it according to your own business code.
When the desktop icon is clicked, the first Activity of the App will be opened. Before the Activity is created, another Application may be created until the Activity's onResume is executed. Only then did you actually see the first page. Before that, it can be understood as the white screen time (using black technology to modify the theme is not considered). So reducing the white screen means reducing the time consumed by these processes, which is simple and crude. The method is to put the initialization of these dependent packages on the Splash page and execute it after onResume
I am too lazy to type...
In fact, when you encounter various problems, you need to solve them yourself. For example, the initialization only takes a few hundred milliseconds, and Splash is too fast If it jumps, you can add a little more practical judgment. For example, if there is no Splash page, you can put the initialization on the homepage, and then perform other operations after initialization. For another example, if you repeat the initialization, you can add a static variable to mark whether it has been initialized.
The summary is to find what The place occupies the time before onResume of the first Activity, for optimization (it may also be image parsing, layout rendering...)

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!