Android 12 SplashScreen API display black after press power button

Viewed 830

UPDATE
If my phone have lock screen, this problem won't happened

I'm using "androidx.core:core-splashscreen:1.0.0-alpha01". The SplashScreen displays well (white background with ic_launcher icon), but there is a problem.
After SplashScreen displayed, I press a power button (phone screen turn off), then I press a power button again (phone screen turn on, status bar display), but the the SplashScreen display black screen. Here is my demo code

themes.xml

<style name="Theme.MySplash" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_background</item>
    <item name="postSplashScreenTheme">@style/Theme.AndroidSplashScreen12</item>
</style>

<style name="Theme.AndroidSplashScreen12" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorOnPrimary">@color/white</item>
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
</style>

AndroidManifest

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AndroidSplashScreen12">

    <activity android:name=".SplashActivity"
        android:exported="true"
        android:theme="@style/Theme.MySplash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

SplashActivity

class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()
        setContentView(R.layout.activity_splash)

        val content: View = findViewById(android.R.id.content)
        content.viewTreeObserver.addOnPreDrawListener { false } // keep SplashScreen display until move to MainActivity
 
        // I will do some long operator here then move to MainActivity
    }
}
1 Answers

its normal to have bug in alpha version. i tried same scenario , sometimes the screen go black . i used this code to pause splash navigation and black screen didn't happened again

SplashScreen.KeepOnScreenCondition {
    !renderMain
}
Related