I am seeing a weird issue with a new app that I am starting. I am utilizing the new Android 12 splash screen API to create my splash screen and I followed the guide provided by Google to do so. I included core-splashscreen in my project to provide compatibility with older versions of Android OS. When I run the app, I see the splash screen as expected on older OS versions like API 30, but when I run it on API 31, the splash screen icon that I provide is not displayed. The background color that I specify is displayed, but the icon is not there at all. I have tried this with a drawable asset as well as a mipmap and nothing is working. I am stumped as every tutorial I find shows the same steps I have followed and screenshots of their working splash screens, but I am not having any luck.
For context here is my splash screen style definition for v31:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">#color/orange_7A</item>
<item name="android:windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
I have an identical style for all other OS versions except I'm using "windowSplashScreenAnimatedIcon" instead of "android:windowSplashScreenAnimatedIcon". I have tried v31 with and without the "android:" in front of the item names and neither work. Here is my MainActivity.kt:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
installSplashScreen()
setContent {
MyVeevaTheme {
Login()
}
}
}
I am also setting the "android:theme" property to my splash style in my AndroidManifest.xml. I know the splash style is being applied because it honors the background color, but it is not showing the icon for some reason even though the icon shows fine for older OS versions. Thanks in advance for any help you can give.
TL;DR kill the app and run from the launcher, icon does not show up when run from Android Studio.
Adding my comment here as an answer for better visibility.
I did figure out how to get it to show. I was following this tutorial to set up a base project to recreate the issue and I noticed the note the author put right near the bottom that mentions that just running the app doesn't show the full splash screen. You have to kill it and open the app from the launcher. Once I did that, I was able to see my splash screen. Annoying, but at least I have a way to test it now. I did go ahead and log a bug report for this as well, but I have a work around for now. Thanks for everyone's answers/comments!
folks as per the document installSplashScreen() should have been called prior to super.onCreate()
When you use the AndroidX SplashScreen Library, like you are doing (Theme.SplashScreen) you need to use the windowSplashScreen* attributes without the android: prefix.
The android: prefix is used to call the platform attributes, but in this case you are using the library and not the platform, so no need for the prefix:
res/values/themes.xml:
<style name="Theme.Splash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/orange_7A</item>
<item name="windowSplashScreenAnimatedIcon">#drawable/splash_foreground</item>
<item name="postSplashScreenTheme">#style/Theme.App</item>
</style>
For some reason when the app is launched through android studio it doesn't show the icon. Kill the app and launch app from the menu. Then the icon will appear.
This is true if you are not using Splash API: https://developer.android.com/develop/ui/views/launch/splash-screen/migrate
Icons are also not shown when navigating from the deeplink.
And It looks like its more then only not showing the icon. It also stops calling code for setOnExitAnimation lambda.
installSplashScreen().apply {
setOnAnimationListener { viewProvider ->
viewProvider.iconView
.animate()
.setDuration(500L)
.alpha(0f)
.withEndAnimation {
viewProvider.remove()
someActionCall()
}
.start()
}
If you relied upon this code to be always called it is not.
See mention in issue tracker: https://issuetracker.google.com/issues/207095799
The following instructions helped me, you may try this one. A few things need to keep in mind while working with the new splash screen API.
Keep updated on the latest library version. Follow this link (https://developer.android.com/jetpack/androidx/releases/core).
Put installSplashScreen() before setContentView()
Make a proper theme for the splash screen. You may try the following one.
Put this into your styles.xml or themes.xml folder and use it with your activity as the theme.
<!-- Splash Screen Theme. -->
<style name="Theme.AppSplash" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">#color/white</item>
<item name="windowSplashScreenAnimatedIcon">#mipmap/ic_launcher_round</item>
<item name="windowSplashScreenAnimationDuration">1000</item>
<item name="postSplashScreenTheme">#style/AppTheme</item>
</style>
Make sure you set the theme to the MainActivity as well. For me that was the cause for the splash screen to now show. So you have to set the theme in both the application and the MainActivity
In addition to the other explanations above, I had the same issue but I realized that in my Manifest file I was setting the Splashscreen theme on my MainActivity which is correct, but my MainActivity was not having the main/launcher intent-filter which tells the android OS that this is the starting activity.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
So in your manifest, check that you are actually setting the Splashscreen theme on the Starting activity that is having the main/launcher intent-filter, and leave the Application tag to have your application theme and not the Splashscreen theme, to avoid having your app misbehave on other activities due to the theme because I experienced that too (This is especially for those migrating to the new splash screen).
Thank you, I hope someone finds this helpful
I had the same problem on my phone running Android 12. None of the above suggestions worked, (moving installSpashScreen() above super.onCreate etc...)
What fixed it for me was adding the android:theme attribute in the manifest to the Launching <activity> Tag, Not the <application> Tag, which is contrary to the documentation :
In the manifest, replace the theme of the starting activity to the theme you created in the previous step.
<manifest>
<application android:theme="#style/Theme.App.Starting">
<!-- or -->
<activity android:theme="#style/Theme.App.Starting">
Note, you still have to kill the activity and launch it from the launcher for this to work :(
In my case, the problem with the lack of a splash screen was the installation of the default activity theme:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name=".App"
android:theme="#style/Theme.Tracker.StartSplashScreen"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:allowBackup="true"
android:dataExtractionRules="#xml/data_extraction_rules"
android:fullBackupContent="#xml/backup_rules"
tools:targetApi="tiramisu">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="#style/Theme.Tracker"> <-------
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
When I deleted android:theme="#style/Theme.Tracker" line, it started working.
Currently I have a very low-res splashscreen I made by setting the applications theme to a drawable image. This would work PERFECTLY if it wasn't for this. Now I'm looking for an alternative.
The one thing I will not do is create a timed splashscreen, which there are plenty of guidelines on how to make one, the one thing I want to know is how do I create a splashscreen that will load first thing, then finish once MainActivity has finished loading?
The one thing I love about my current splashscreen is that it loads instantly when the app starts, but it will cause major delays when clicking buttons if it's high-res (more than 300x300pixels).
Here's my current code for the flawed, laggy splashscreen that loads and stops based on MainActivity's loaded state:
in styles.xml:
<style name="splashscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowBackground">#drawable/splashscreen</item>
</style>
in manifest:
in AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:fullBackupContent="false"
android:theme="#style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/splashscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Check for possible issues with overdraw. It seems that the background (the splash image) is still there. see http://www.curious-creature.org/2012/12/01/android-performance-case-study/ if it applies to your case.
Removing the window background: the background defined in your theme is used by the system to create preview windows when launching your application. Never set it to null unless your application is transparent. Instead, set it to the color/image you want or get rid of from onCreate() by calling getWindow().setBackgroundDrawable(null).
I wanted to add a SplashScreen to my app and did a little research on the matter. Some tutorials said that you could create an activity and with some timers show it for a few seconds. I couldn't get them working, and then in this page How do I make a splash screen? the second top voted answer said that instead of showing an activity (and because of that wouldn't substitute the white/black launch loading screen but instead add more delays) you should instead create a custom style and assign it to your activity in the Manifest file. I did that, created a new Style like this:
<style name="splashScreenTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/launchscreen</item>
</style>
in the styles.xml and changed my Manifest to this:
<application
android:name=".EFBApp"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivityDrawer"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/splashScreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When I run my app I can see the launch screen perfectly but then it crashes. By breakpoints I discovered that when the MainActivityDrawer (my main class) gets to the super.onCreate(savedInstanceState); line it then crashes (it goes to the ZygoteInit.java class and after that it crashes while breakpoint debugging). If I take away the android:theme lines in the Manifest it works fine but shows the horrible plain white screen while launching. Any suggestions or ideas? Thanks a lot.
Ok, so I managed to make it not crash, instead of assigning the parent as Theme.AppCompat.NoActionBar, I used just AppTheme and it works now. I hope this helps anyone.
I want to override a application theme on a particular activity, but its not working for me
This is code on my Manifest.xml:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock.Light" >
<activity
android:theme="#style/MyTheme"
android:name="com.ssdevnet.Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ssdevnet.Home"
android:label="#string/app_name" />
</application>
And this is what i used in style:
<style name="MyTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:windowNoTitle">true</item>
</style>
and its still not working on Android 2.3.6 or below but working on 3 and above.
Also i tried to use this on the oncreate method on class file for that particular page:
requestWindowFeature(Window.FEATURE_NO_TITLE);// Removes title bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Removes notification bar
but its not working on my phone running Android 2.3.6 but its working on Emulator running Jellybean and i need something that works on all the versions.
And I need to know some things as i am a newbie to android:
Can we define a Global theme, and override that theme on some activities? if yes, what method can we use?
Or we have to define theme for every activity if we are targeting activities instead of app?
I also want to learn about deploying the custom themes in the app.. if there are some good tutorials and references please share.
Thanks in Advance!
Try using setTheme(..) before calling setContentView(...) and super.oncreate() and it should work fine in the Activity.
Check out the Android developer's site for more information.
My goal is to show a splash screen on my applications startup. Right now what it will do is briefly show the actionbar with an otherwise blank page, then jump to the splash screen. I'm trying to figure out how to not show the beginning screen and just start with the splash screen.
I'm trying to use these links for information on how to solve this.
ActionBar Lag in hiding title
In this one I'm assuming I can use the same type of method for hiding the actionbar by changing the theme, but I don't know what I would actually use as my style to do so.
How to hide action bar before activity is created, and then show it again?
and here it talks about adding a line to the manifest that would do it. Where in the manifest? Anywhere I put it did not do anything.
try this in manifest file
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
Check this link Android: hide action bar while view load
Code snippets from the link, incase the link breaks down, courtesy #kleopatra:
Setting the properties windowNoTitle to true on your theme will
hide the ActionBar. use two different themes both extending parent="Theme.AppCompat.Light" in order to prevent NPE when using getSupportActionBar
set the styles as
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppThemeBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
</style>
Due to some odd behaviour on versions < 11, you need to add
if (Build.VERSION.SDK_INT < 11){
getSupportActionBar().hide(); }
inside activities that do not need the actionbar
Delete the "android:label" entries in Manifest file, from application and the first activity which is loaded. In your case, the Splash activity.
Sample...
<application
android:allowBackup="true"
android:icon="#drawable/starticon"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<activity
android:name=".ActivitySplash"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Just add this code in your Activity in the onCreate function.
val actionBar = supportActionBar?.apply{hide()}