Splash Screen Migration To Android 12

Junaid Ahmad
2 min readSep 18, 2021

Android 12 SDK beta version is now available which includes some behavior changes for those apps which are targeting Android 12 SDK. It means that if you are application has compileSdkVersion 31 or above it will start affecting due to these changes. Check here more behavioural changes of Android 12.

When we start our application targeting Android 12, the system always applies this default splash screen to the apps. By default, it will pick the app icon and the background color from the application theme for the splash screen.

The apps with custom splash activity will show duplicated splash screens if running on Android 12 devices.

So let’s see how we can migrate our existing Splash Screen to the new Android 12 Splash API.

1. Change SDK Version

Open module `build. gradle` file and change the following fields.

android {
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
targetSdkVersion 31
}
...
}
dependencies {
...
implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
}

Please note that you will need to have a version 4.2 or above of Android Studio for these changes.

2. Create Theme

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/...</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/...</item>
<item name="windowSplashScreenAnimationDuration">200</item>
<item name="postSplashScreenTheme">@style/Theme.App</item>
</style>
  • windowSplashScreenBackground This attribute is used for the splash background colour.
  • windowSplashScreenAnimatedIcon This is used for setting animated or just drawable.
  • windowSplashScreenAnimationDuration This is required if you set the animated icon as drawable.
  • postSplashScreenTheme Takes the theme of the Activity that directly follows your splash screen.

3. Change Theme in Manifest file

<application
...
android:theme="@style/Theme.App.Starting">
<activity
android:name=".ui.MainActivity" android:exported="true">
<intent-filter>
...
</intent-filter>
</activity>
...
</application>

In Android 12 it is mandatory to mention the exported value true/false for activity in Manifest file. Since we are using the Intent filter in our activity therefore we set it to true.

I suggest you read more about the show the rationale for data access here

4. installSplashScreen() and Exit Animation

class MainActivity: Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Handle the splash screen transition.
val splashScreen = installSplashScreen()

setContentView(R.layout.main_activity)
setSplashExitAnimation(splashScreen)
}

private fun setSplashExitAnimation(splashScreen: SplashScreen) {
splashScreen.setOnExitAnimationListener { splashScreenView ->
configureObjectAnimator(splashScreenView) { slideUpAnimation ->
with(slideUpAnimation) {
interpolator = AnticipateInterpolator()
duration = 500L
doOnEnd {
splashScreenView.remove()
}
start()
}
}
}
}

private fun configureObjectAnimator(
splashScreenView: SplashScreenViewProvider,
onComplete: (ObjectAnimator) -> Unit
) {
val objectAnimator = ObjectAnimator.ofFloat(
splashScreenView.view,
View.TRANSLATION_Y,
0f,
-splashScreenView.view.height.toFloat()
)
onComplete.invoke(objectAnimator)
}

Here is the Github repo for Android Splash Migration https://github.com/JunydDEV/android-dayplanner-app

--

--

Junaid Ahmad

Android Engineer @Callsign — I write about new things in Android.