Prateek Gupta
Prateek Gupta

Reputation: 2800

Splash Screen not working with Deep links and when launched from Android Studio

When I launch my app from launcher screen the Splash Screen works fine enter image description here

but when I launch my app via deep link, the logo animation is not triggered and also the code in the associated SpalshScreen.OnExitAnimationListener object is not called enter image description here

Manifest.xml

<activity
            android:name=".main.MainActivity"
            android:configChanges="orientation|screenSize"
            android:theme="@style/SplashScreenTheme"
            android:exported="true"
            android:screenOrientation="portrait">
            <intent-filter>
                <data
                    android:host="prateekgupta.pythonanywhere.com"
                    android:scheme="https" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <action android:name="android.intent.action.VIEW" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

theme.xml

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
        <item name="windowSplashScreenBackground">@color/logo_bg</item>
        <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen_logo_animation</item>
        <item name="windowSplashScreenAnimationDuration">2000</item>
        <item name="postSplashScreenTheme">@style/MainTheme</item>
    </style>

MainActivity

SplashScreen splashScreen = SplashScreen.installSplashScreen(this);

splashScreen.setOnExitAnimationListener(splashScreenViewProvider -> {
            TranslateAnimation translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_PARENT, 0f,
                    Animation.RELATIVE_TO_PARENT, -1f,
                    Animation.RELATIVE_TO_PARENT, 0,
                    Animation.RELATIVE_TO_PARENT, 0f);
            translateAnimation.setDuration(1000L);
            translateAnimation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {

                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    splashScreenViewProvider.remove();
                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });

            // Starting exit animation of SplashScreen
            splashScreenViewProvider.getView().startAnimation(translateAnimation);
        });

Is I'm missing something, because the same issue also occurs when I launch my app in my physical device with Android 12 from Android Studio.

Upvotes: 4

Views: 1144

Answers (1)

nullPointttt
nullPointttt

Reputation: 31

<style name="SplashScreenTheme" parent="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@color/logo_bg</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/splash_screen_logo_animation</item>
    <item name="windowSplashScreenAnimationDuration">2000</item>
    <item name="postSplashScreenTheme">@style/MainTheme</item>
    <item name="android:windowSplashScreenBehavior">icon_preferred</item>
</style>

Adding this line <item name="android:windowSplashScreenBehavior">icon_preferred</item> makes the icon display correctly even when executing deep links.

Upvotes: 3

Related Questions