Search code examples
androidandroid-splashscreen

Android 12's Splash Screen API- Getting white screen after Splash Screen on some below Android 12 devices


I have a dedicated SplashScreen Activity and on this activity, there is one API call (once in a lifetime), SDK initialization, setting default values for Firebase RemoteConfig, and routing logic. It's working fine as expected on some devices, but on some devices, I'm getting a white screen after displaying SplashScreen.

List of devices on which I did testing for it:

  1. Samsung s20 fe (Android 12) - working as expected
  2. OnePlus (Android 11) - working as expected
  3. MI (Android 11) - getting a white screen
  4. Moto G5 Plus (Android 8) - getting a white screen

Note: Above mentioned business logic doesn't take much time to get process, please check following logs

2022-11-01 15:24:13.146  5905-5905  V  OnCreate
2022-11-01 15:24:13.177  5905-5905  V  SplashScreen.installSplashScreen
2022-11-01 15:24:13.275  5905-5905  V  setKeepOnScreenCondition
2022-11-01 15:24:13.282  5905-5905  V  onTaskComplete
2022-11-01 15:24:13.297  5905-5905  V  nextScreen
2022-11-01 15:24:13.315  5905-5905  V  User details is not null in SplashScreen
2022-11-01 15:24:18.716  5905-5905  V  onDestroy

Manifest File

   <activity
        android:name=".splashscreen.SplashScreenActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:theme="@style/Theme.App.Starting">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

value/styles

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_impact</item>
    <item name="windowSplashScreenAnimationDuration">500</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>

value/styles (v31)

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_impact_anim</item>
    <item name="windowSplashScreenAnimationDuration">1000</item>
    <item name="postSplashScreenTheme">@style/AppTheme</item>
</style>

SplashScreenActivity

    @Override
protected void onCreate(Bundle savedInstanceState) {
    SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
    super.onCreate(savedInstanceState);
    splashScreen.setKeepOnScreenCondition(() -> true);
    Utils.initThirdPartySdk();
    initiateRemoteConfig();
}

//at last calling nextScreen()
 private void nextScreen() {
        Timber.v("nextScreen");
        boolean userLogin = MainApplication.isUserLoggedIn();
        if (userLogin) {
            Timber.v("User details is not null in SplashScreen");
            showMainActivity();
        } else {
            Timber.w("User details is null in SplashScreen, opening LoginActivity");
            showLoginActivity();
        }
        finish();
    }

private void showMainActivity() {
    Intent intent = new Intent(SplashScreenActivity.this, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    startActivity(intent);
}

Solution

  • This issue was about switching activity, so removing the following line of code for calling MainActivity will solve the problem.

    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);