Getting Warning Application should not provide its own Splash Screen in Android Studio

Viewed 17019

I have recently changed my Target SDK Version to 31 (Android 12) and after upgrading I started getting this warning:

The application should not provide its own launch screen.

This is the screenshot:

enter image description here

So why I'm getting this warning, is there any better approach to create Splash Screens or should I just ignore the Warning?.

3 Answers

There is better approach now. For Android 12, there is brand new Splash Screen Api which works on previous versions aswell, see more here

It supports theming, custom animations and is super simple to use.

Just change the name, without using "splash" in it.

Starting in Android 12, the SplashScreen API enables a new app launch animation for all apps when running on a device with Android 12 or higher. This includes an into-app motion at launch, a splash screen showing your app icon, and a transition to your app itself.

TLDR; Android provides a new API for integrating SplashScreen. First, remove the SplashScreen then follow below code block.

Add in build gradle implementation 'androidx.core:core-splashscreen:1.0.0-rc01'

follow the below steps.

Define:

<style name="Theme.App.Starting" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/ed_colorPrimary</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_logo</item>
    <item name="windowSplashScreenAnimationDuration">200</item>
   <!-- Set the theme of the Activity that directly follows your splash screen. -->
    <!-- Required -->
    <item name="postSplashScreenTheme">@style/Theme.MyAppTheme</item>

</style>

Then in Manifest check and verify that you given Theme.App.Starting

<application
    ...
    android:theme="@style/Theme.App.Starting" > 
    ...
    <activity
        android:name=".ui.MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Finally, Don't forget to add.

class MainActivity : BaseActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val splashScreen = installSplashScreen()
        ...
Related