- Implementing the Perfect Splash Screen in Android
- Splash Screen is the first screen visible to the user when the application’s launched. It’s a vital screen that will allow the users to have first impressions of the application.
- There are 2 common methods of implementing splash screens and will find the right way:
- Step 1
- Step 2
- Step 3
- Step 4
- Step 5
- Now that our splash is working, what size of the image should I put into a drawable folder?
- Splash screen best practices
- The (Complete) Android Splash Screen Guide
- Using a Launcher Theme
- Using a Launcher Theme with a Dedicated Splash Activity
- Using Timers
- Using Smart Timers
- New Splash Screen In Android
- Introduction
- How the splash screen works
- Initializing Splash Activity
- Traditional Approach
- The old way,
- Modern Approach
- Step 1
- Step 2
- Final Step
- — Recently,
- Let’s test Splash by Upgrading to — Android 12,
- To Fix Installation failed ?👼
- Now For Splash Screen,
Implementing the Perfect Splash Screen in Android
Splash Screen is the first screen visible to the user when the application’s launched. It’s a vital screen that will allow the users to have first impressions of the application.
A Splash Screen is a screen that appears when you open an app on your mobile device. Sometimes it’s referred to as a launch screen or startup screen and shows up when your app is loading after you’ve just opened it.
When the loading is finished, you’ll be taken to a more functional screen where you can complete actions.
Splash screens appear on your screen for a fleeting moment — look away and you might miss them. The splash screen is one of the most vital screens in the application since it’s the user’s first experience with the application.
There are 2 common methods of implementing splash screens and will find the right way:
- Using Timers (the bad)
- Using a Launcher Theme (The Right way)
Using timer (Our 1st Method) into your activity to display splash, we create a splash activity and create a thread in onCreate() for shows up for 2/3 seconds, then go to our desired activity. Here, see the implementation of this easy method:
The above approach isn’t the correct approach. It’ll give rise to cold starts.
The purpose of a Splash Screen is to quickly display a beautiful screen while the application fetches the relevant content if any (from network calls/database). With the above approach, there’s an additional overhead that the SplashActivity uses to create its layout.
It’ll give rise to slow starts to the application which is bad for the user experience (wherein a blank black/white screen appears).
The cold start appears since the application takes time to load the layout file of the Splash Activity. So instead of creating the layout, we’ll use the power of the application theme to create our initial layout (Our 2nd Method).
Application theme is instantiated before the layout is created. We’ll set a drawable inside the theme that’ll comprise the Activity’s background and an icon using layer-list as shown below.
Do you know when an activity is called Android OS first see in the manifest is there any theme for that activity and load the theme from manifest?
So, we will set a custom theme in Manifest for our splash activity. To create the theme for the splash screen, follow the below process.
Step 1
Create Background for Splash Screen in drawable/splash_background.xml, the bitmap is the image we want to show.
Step 2
Create the gradient onto which your app logo will be placed in drawable/bg_gradient.xml, background can be a gradient or any colour depending on your app.
Step 3
Create Style for Splash Screen in res/values/themes.xml
Step 4
Create an empty Activity named SplashScreenActivity and set the style as the theme for it in AndroidManifest.xml
Step 5
Setting the Intent to your MainActivity.java from SplashScreenActivity.java
As we are loading the splash screen them from manifest, there is no need to setContentView() with any xml layout. If you want to show your splash screen for some amount of time (like five secs) you can create a Handler , also using a timer can help you fetch data from the cloud on your MainActivity which could be a better approach than to show a dialog on home screen.
Using the theme and removing the layout from the SplashScreenActivity is the correct way to create a splash screen 🙌.
Now that our splash is working, what size of the image should I put into a drawable folder?
Always put your app_logo.png into drawable-xxhdpi folder so that your logo automatically scales for all types of phone screens in most cases.
Also, make sure that image resolution is not more than 1000×1000 pixels . It can have less resolution depending on how you want it. Now there are diverse types of splash screen which has multiple logos on various parts of the screen. How that could be done?
From the above example, we implemented our method to create a splash like Twitter, and now to create one like Facebook we just make a slight change to our drawable/splash_background.xml.
Just add as many item to your layer-list you want to place in your splash screen.
Splash screen best practices
Splash screens are simple. They’re used to enhance a brand and give users something nice to look at as they wait. In this regard, here are some best practices for when you design your own splash screen:
- Keep it free from unnecessary distraction
- Don’t use multiple colours or logos
- Use animation sparingly
Hope it helped. Happy Coding 😀
BTW, I solve real-world problems by building useful apps. Have a look at my portfolio .
Источник
The (Complete) Android Splash Screen Guide
Dec 6, 2017 · 5 min read
In the past, having splash screens in your Android app were not recommended. It didn’t make much sense to intentionally delay the user by adding a splash screen that shows for x seconds. Am sure no one launches an app just to see a splash screen (more on this later).
Getting users to the content they care about should be your #1 priority
Well, when Material Design dropped with a pattern called Launch Screen (Splash Screen), someone from the Android team shared a post on how to do splash screens the ‘right’ way.
In this post I will walk through 4 common methods of implementing splash screens on the Android platform:
- Using a Launcher Theme ( The good)
- Using a Launcher Theme with a Dedicated Splash Activity ( The okay)
- Using Timers ( The bad)
- Using Smart Timers ( The ugly)
Using a Launcher Theme
Wh e n your app is launched and it isn’t in memory yet, there may be some delay between when the user starts your app and when your launcher Activity’s onCreate() is actually called.
During the ‘cold start’, the window manager tries to draw a placeholder UI using elements from the app theme like the windowBackground . So, rather than showing the default windowBackground (usually white or black), you can change it to a custom drawable that shows your splash screen. This way the splash screen only shows when needed and you don’t slow down your users.
The key is creating a custom theme that overrides android:windowBackground , then replacing that custom theme with your standard theme before calling super.onCreate() in your Activity.
In this example, I will assume your app main theme is named AppTheme, but if it’s not then you can replace all occurrence of AppTheme with the name of your app main theme.
You will have to create a new theme for the launcher. The only element we are interested in overriding in this theme is the windowBackground , so the launcher theme will be:
To inherit every other attribute in your main theme, the dot notation was used by prefixing the name of the theme ( AppTheme), separated by a period ( .).
Let’s define the launch_screen drawable. While you could just use a simple image, it will end up stretched to fill the entire screen. Instead, you can use an XML file such as:
Then apply the launcher theme to your launcher Activity in your AndroidManifest.xml file using:
The easiest way to transition back to your normal theme in your launcher (main) activity is to call setTheme(R.style.AppTheme) before super.onCreate() and setContentView() :
You can read more about this approach from the source here.
- No launch/splash activity needed — there is no delay such as there would be if you were launching a second activity from a dedicated splash screen activity.
- No artificial delays — No intentional x seconds delay. Only showing the splash screen when the system is loading up the app.
I have seen 3 very common complains about this approach.
- The splash screen showing again if the activity was killed and recreated by the system. In most cases, this is not a very serious issue, but you can use Method 2 to fix it.
- Some developers want to have a dedicated splash screen Activity that routes to different pages based on some state after the splash screen is done. Again you can easily do this using Method 2 below, but sometimes this dedicated router Activity end up getting really messy.
- Not able to load heavy data/components while the splash screen is shown. It’s usually a bad idea to require heavy data or components to be loaded before the app is actually started (there are some exceptions). You can try one of the suggestions below:
i) Try to lazy load your components/modules/libraries. Except a component is really really required for the app to work, try not to load it at launch time rather load it when you need it or use a background thread to load it after the app has started. Try to keep your Application onCreate() as light as possible
ii) Make use of caching. Except that info changes very frequently, you should cache it. So when next the user comes to your app, you can show this cached content while you load more recent content.
I think we should strive to remove things like long splash screens, ProgressDialogs that make the user unable to perform any other action apart from just staring at the screen. You never know how long it will take to load that data from the Internet.
If your app connects to the web, assume that anything that can go wrong will go wrong. This way you can build for the millions of people still using unstable 2g and 3g connections.
Using a Launcher Theme with a Dedicated Splash Activity
This method builds on top Method 1. It requires you to have a dedicated splash screen Activity. This allows you to quickly solve the first 2 issues in Method 1.
All you have to do in this step is to create a new splash Activity and assign the launcher theme to it in your AndroidManifest.xml file (Like in Method 1). Then edit your splash activity to route to the various pages. Look at the example below:
- Solves the first two issues listed in Method 1.
- I have seen this routing thing easily get ugly.
- Small delay transitioning between Activities.
- It’s easy to forget and start doing some long running operations here.
Using Timers
This is the old easy approach. You just have to create a dedicated splash screen Activity that shows up for x seconds, then opens the appropriate activity. You get more flexibility here as you can add animations, custom views or any other element you can normally fit into an Activity layout. A very basic implementation of this will look like this:
- You get a chance to show your awesome animation or some custom design you have built. This really makes sense for games or apps directed to kids.
- More flexibility on what you can do on the splash screen.
- Double whammy — Your launcher Activity usually doesn’t show up immediately when the app is launched, especially when your app is cold starting. The user waits for the cold start looking at only the windowBackground and then waits for your splash screen again before getting to your app content.
- Your awesome animation or design usually only amaze the user the first few times. After that, most users will find it boring and they want to get to the content. I think Method 4 provides a fix for this.
- Most times the extra delay is not worth it.
Using Smart Timers
This builds on Method 3. So rather than make the delay fixed, you vary it based on whether the user is launching the app for the first time or not. Here is an example using SharedPreferences :
Inherits all Method 3 pros.
- This might fix the issue of the user getting tired of seeing your splash screen showing up for a long period of time.
- Double whammy — The issue in method 3 still exists here
- Most times the extra delay is not worth it.
- I haven’t used this method before, but I think there might be some lag while reading from storage.
Okay, so that’s it for splash screens on Android. If I missed any other common implementation, please let me know in the comment section below.
Источник
New Splash Screen In Android
A better way to display Android Splash Screen. #Android12
🚣 Hi, In this article we learn to implement splash screen in android. From OLD traditional way to NEW modern way.
Introduction
Android Splash Screen usually the first screen that is displayed to the user when an app is not fully ready to display content.
How the splash screen works
When a user launches an app while the app’s process is not running (a cold start) or the Activity has not been created (a warm start), the following events occur. (The splash screen is never shown during a hot start.)
- The system shows the splash screen using themes and any animations that you’ve defined.
2. When the app is ready, the splash screen is dismissed and the app is displayed.
Now let’s dive in,
Initializing Splash Activity
First, To launch the activity as splash screen we just need to add the action main and category launcher to your activity in AndroidManifest.xml
Traditional Approach
The old way,
We used to pause the user interaction for like 2–3 sec for a splash screen to load.
UI Holding was never an option. As in Activity we used to write these horrific code… and activity used to look like shi**.
This used to work well back then & now too, but we all knew there should be something more than just waiting.
Modern Approach
With a new approach, we don’t declare a time to wait.
Step 1
First, Gather all necessary elements for splash screen like colors & logo.
Then, Create drawable placing logo as bitmap/drawable.
Step 2
In style declare a any desired theme for splash screen and set android:windowBackground attribute value to drawable we created.
The android:windowBackground attribute will show our created drawable on activity transition.
And, In AndroidManifest.xml we add our theme as.
Final Step
To hide content of splash screen layout, in activity remove setContentView(),
As to show created drawable as a transition between these splash & another activity we won’t be needing splash layout.
Here’s the source code… if you need.
Done. The modern approach is more convincing than our traditional approach.
Continue to read more on Android 12 Splash Screen
— Recently,
Android 12 adds the SplashScreen API, which enables a new app launch animation for all apps. This includes an into-app motion at launch, a splash screen showing your app icon, and a transition to your app itself.
The new experience brings standard design elements to every app launch, but it’s also customizable so your app can maintain its unique branding.
This is similar to our modern approach.
Read more at the official website.
Let’s test Splash by Upgrading to — Android 12,
After upgrading, From NoWhere, Boom A error popups and your application installation failed.
Installation did not succeed.
The application could not be installed: INSTALL_FAILED_VERIFICATION_FAILURE
List of apks:
[0] ‘…/build/outputs/apk/debug/app-debug.apk’
Installation failed due to: ‘null’
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI:
Targeting S+ (version 10000 and above) requires that an explicit value for android:exported be defined when intent filters are present”
To Fix Installation failed ?👼
Now For Splash Screen,
For testing the effects & changes let’s observe with WHITE & BLACK color background first.
Create new styles.xml or theme.xml (v31).
As mentioned, It’s similar to our modern approach.
The only Difference is , we need to remove android:windowBackground for Android 12.
By default your launcher icon will act as a splash screen view.
No need to create drawable. Just add your launcher icon & Kaboom it’s a splash screen logo.
As documented, SplashScreen uses the windowBackground of your theme if it’s a single color and the launcher icon. The customization of the splash screen is done by adding attributes to the app theme.
But it can be customized in many ways. Amazing and simple right?
Источник