Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splash screen does not work on android 12 devices #497

Closed
developer9969 opened this issue Aug 8, 2022 · 12 comments · Fixed by #510
Closed

Splash screen does not work on android 12 devices #497

developer9969 opened this issue Aug 8, 2022 · 12 comments · Fixed by #510
Labels
Android bug Something isn't working

Comments

@developer9969
Copy link

developer9969 commented Aug 8, 2022

Hey,
Just to let you know that if you run the app against an android 12 device/emulator and you will see a blank screen when loading the app. All good on android when <=11

@brminnick
Copy link
Owner

Oh goodness! Thank you for letting me know!

I'll prioritize this bug this week 🙌

@brminnick brminnick added bug Something isn't working Android labels Aug 8, 2022
@brminnick
Copy link
Owner

It seems Google has changed the way splashscreens work in Android 12:
https://developer.android.com/guide/topics/ui/splash-screen/migrate

@developer9969
Copy link
Author

Hi
Well I have done a bit of research and below are my conclusion

  1. We are well screwed.
  2. If you have an android 12 device - currently it will only show your app icon
  3. if you have a slighter fancier splashscreen - say good bye to it - as it will show cut off
  4. The trend before was to use a layer_list and then put an icon there using a separate splash_screen - that is no longer required
  5. you just need to do the following
    <style name="Theme.SimpleSplash.Starting" parent="Theme.SplashScreen.IconBackground">
		    
		    <!--<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher</item>-->
		    <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_foreground</item>
		    <item name="windowSplashScreenIconBackgroundColor">@color/ic_launcher_background</item>
		    <item name="windowSplashScreenBackground">?android:colorBackground</item>
		    <item name="postSplashScreenTheme">@style/AppTheme</item>
    </style>
  1. Your android manifest to call Theme.SimpleSplash.Starting -
  2. Remove splash activity
  3. AppTheme - will be your main theme to fall back to
  4. And the more important of all is that your icon size is

image

Bottom line - we are stuffed unless I am wrong an missing the obvious..

Despite various attempt no help or explanation was given by either xamarin forms team or xamarin android , you might have better luck as you have connections with them.. if you do and you find something different can you post it -blog it etc..

All the apps are now broken!!

@developer9969
Copy link
Author

Ah - forgot the main bit you have to reference
image

and Main Activity - remove any reference to theme in the attribute
and put this AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this); before create

@brminnick
Copy link
Owner

brminnick commented Aug 13, 2022

Turns out the fix is a bit easier than the Android docs let on.

tl;dr - You don't need to add a new NuGet Package; you don't need to create a new style / theme

Create New Icons

  1. For each display density, create a new file, sized 288dp
  2. Inside each new file, center a new icon for each display density that contains the app logo inside of a 192dp-radius circle
  3. Add the new files to the corresponding folders in /Resources/drawable*

Create new adaptive-icon

  1. Create New Folder, /Resources/drawable-v26
  2. In /Resources/drawable-v26 add a new file, splashscreenanimatedicon.xml
  3. In splashscreenanimatedicon.xml, create a new adaptive-icon:
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/splash_screen_background" />
    <foreground android:drawable="@drawable/splashscreenanimatedicon" />
</adaptive-icon>

Update styles.xml

  1. In your existing splash screen theme, add android:windowSplashScreenBackground and android:windowSplashScreenAnimatedIcon:
<item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splashscreenanimatedicon</item>

@developer9969
Copy link
Author

@brminnick Let me digest what you did and see if it works for me too :) .
I am pleased that there is another solution I can explore
Can I ask you why /Resources/drawable-v26? Any particular reason?
So for your splash screen youre are using "splashscreenanimatedicon.png" but what about your "splash_screen.xml" is that still used?

Am I trying to piece together what I need todo and usually I work with forms and hardly touch this side of things...
Many thanks for your time!

@brminnick
Copy link
Owner

brminnick commented Aug 15, 2022

Good Questions!!

Why Use /Resources/drawable-v26?

The new splash screen resource (android:windowSplashScreenAnimatedIcon) requires a adaptive-icon. However, the adaptive-icon API was added in Android API v26. Putting it in the /drawable-v26 folder tells Android to only include this resource in v26 and up. The rule is that files included in drawable-vXX will only be included for devices running Android API XX and up.

I other words, I did this to ensure GitTrends continues to be backwards compatible to Android API v23.

Is the Old Splash Screen Still Being Used?

Yes! My Launch Theme (aka the Theme of my MainActivity) still uses [Theme = "@style/LaunchTheme"], and LaunchTheme still includes android:windowBackground which is my original splash screen, @drawable/splash_screen (all of this code existed before this PR and remains unchanged):

<!-- GitTrends' Launch Theme -->
<style name="LaunchTheme" parent="Theme.AppCompat">
  <!-- Item's That Existed Before Android API v31, Still used (only) on Android v30 and below -->
  <item name="android:windowBackground">@drawable/splash_screen</item>
  <item name="android:windowNoTitle">true</item>
  <!-- Item's Added to Support Android API v31, Only Used on Android API v31+-->
  <item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
  <item name="android:windowSplashScreenAnimatedIcon">@drawable/splashscreenanimatedicon</item>
</style>

On Android API v31 And Up

When the app runs on Android v31+, it checks the Launch Theme for two values:

Android uses these two values for the Splash Screen and ignores the other values in the style.

On Android API v30 And Below

When the app runs on Android v30 (and below), it doesn't know about the new APIs added in v31, so when it sees android:windowSplashScreenAnimatedIcon, and android:windowSplashScreenBackground, it ignores these values.

Android just checks the Launch Theme for android:windowBackground, which still points to my original launch screen, splash_screen.xml, which uses a layer-list.

In other words, yup, keep the old splashscreen around and keep it in the Launch Theme. Android will automatically use the values it needs based on the version of the operating system.

@developer9969
Copy link
Author

FANTASTIC! thanks for this detail explanation, I will try to put first together a noddy blank form and see if all works and if it does than I will roll it out to the real production apps.

I was really stuck on this one - hopefully I get it ....

thanks for your time!

@brminnick
Copy link
Owner

brminnick commented Aug 15, 2022

Before Android v12.0 After Android v12.0 (broken) After Android v12.0 (Fixed)
ScreenFlow2 ScreenFlow ScreenFlow

@developer9969
Copy link
Author

developer9969 commented Aug 16, 2022

@brminnick wow. Excellent! one more question - I have seen you article (brilliant) - Really needed

You say "The splash screen icon should match our app's icon" . Can the splash image icon be different from the app icon and still work?

thanks

@brminnick
Copy link
Owner

Thanks for the kind words!

Can the splash image icon be different from the app icon and still work

Technically speaking, yes it'll work. But Android's guidance is for them to match. I don't know if Android is enforcing this. They may fail your app when in review before submitting to the App Store. I'm not sure.

@developer9969
Copy link
Author

brilliant thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants