运行 调试变体时启动时出现白屏

White screen at start when running debug variant

最近,我注意到 运行我第一次安装应用程序的 debug 变体 - 意思是 第一次安装它,一个 白屏 出现在启动画面 之前 ,它会持续很长时间 ~ 15 sec on Nexus 6

如果我清除数据,然后再次 运行,也会发生这种情况。

起初我认为这是任何补丁的副作用,所以我回滚到工作发布的修订版

但同样的事情发生了。虽然如果我从 Play 安装, 它可以正常工作

所以,我 运行 构建了 'release',瞧!它工作正常。这显然不是由应用程序 class 或任何其他代码更改引起的,因为发布时也会发生这种情况。

也明显和别处提到的短白屏问题不一样,像这样(): 因此,当我按照那里的建议将 transparent theme 应用到 splash 时,点击应用程序后,phone 屏幕冻结 相同的时间 内没有触摸 ,然后显示 Splash

不知道为什么更改为 debug 会导致如此大的问题。而为什么先运行而已。

这是因为您正在使用 Android studio instant 运行。

您可以这样禁用它:

Properties -> Instant Run -> uncheck 'Enable Instant Run...'

根据我的经验,当您使用应用程序时请忽略此问题,但是当您向 client/tester 提供构建时,请进行签名构建并在您的设备中检查相同的问题解决。尽管如此,我还是找到了完美的调试解决方案,直到您可以使用它为止。 (这只发生在 API 24 岁及以后)。

制作一个像这样的可绘制对象,名称为 background_splash

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/gray"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher"/>
    </item>

</layer-list>

然后在样式中添加这样的样式:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

然后在清单中的 activity 添加您的样式

<activity
    android:name=".SplashActivity"
    android:theme="@style/SplashTheme">

更多信息: Splash Screens the Right Way

您还可以查看 android 表演模式剧集: android performance patterns

如果您已将 android:debuggable="false"" 放入清单文件 改成

android:debuggable="true"

或 属性 -> 即时 运行 -> 取消选中 'Enable Instant Run...'

属性 -> 即时 运行 -> 取消选中 'Enable Instant Run...'