Active1 month ago
I am using android studio 2.2.3. I included a splash screen in my program.but it is not working. Splash screen activity does not showing .it directly enter in to the homepage.`Manifest file
It is a constant screen which appears for a specific amount of time, generally shows for the first time when the app is launched. The Splash screen is used to display some basic introductory information such as the company logo, content, etc just before the app loads completely.
`
SplashScreen activity
Mauricio Gracia Gutierrez5,85133 gold badges4141 silver badges6161 bronze badges
suhail mcsuhail mc
5 Answers
SrdanSrdan
Remove the
<intent-filter>
from the MainActivity if you want the SplashActivity to be the entry point of your application. Splash screen activity does not showing
You have two icons for your app in the launcher at the moment. You need to open the SplashActivity instead of the MainActivity
cricket_007cricket_00791.3k1111 gold badges5757 silver badges139139 bronze badges
Mark Keen5,23644 gold badges1818 silver badges4747 bronze badges
ekawasekawas5,35033 gold badges2121 silver badges3838 bronze badges
I know this was posted a while ago, but there was never a true answer!
What you need to do is NOT just remove:
But to cut them, and MOVE them into an additional
<activity android:name='.Splash'>
So the final code would look like:
user2592356user2592356
You have written this chunk of code two times.You can just remove it from the MainActivity part. It worked out for me.
Laura MessnerLaura Messner
Not the answer you're looking for? Browse other questions tagged androidsplash-screen or ask your own question.
Android Splash Screen is usually shown at start of the application for 2 or 3 seconds of time.
Main purpose of Android Splash Screen is to show logo and name of the application to user.
Sometimes it is also used for fetching required data from remote server before starting the app.
Splash screen is a simple screen or activity used to display some progress when application is launched.
Some developers use splash screen to just show company logo or to engage user while some important data in loaded in background.
After few seconds or minutes, splash screen is stopped and any other activity is started.
An Androidapp takes some time to to start up, especially when the app is first launched on a device.
A splash screen may display start up progress to the user or to indicate branding.
Latest purpose of splash screen can be found as you can ask for all permissions you are using in application.In all android versions after MARSHMALLOW, you have to request for permission to user. You can learn how to request for permission to user in this demo.
You can implement Splash Screen in many ways in Android. But I have shown easiest and quickest way to implement splash screen.
If you want some animation and cool effects in your splash screen, then visit following tutorials.
Following is the output of splash demo:
Step 1. Create new project
Create a new project in Android Studio with Empty Activity.
Step 2. Code for splash
Copy and paste following code in activity_main.xml file:
2 4 6 8 10 12 | <RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' tools:context='.MainActivity'> <ImageView android:layout_height='match_parent' android:src='@drawable/splash'/> |
We have taken an ImageView with full size of screen.
You need to make a separate image for splash.
This image may contain company name and/or logo with or without brand’s slogan.
Splash Image Size
You need to make different size of splash images for different android device screens.
There may be a small variations among various image sizes and screen sizes.
I am going to give you a dimensions which can be used generally in most of the cases.
- LDPI:
- Portrait: 200x320px
- Landscape: 320x200px
- MDPI:
- Portrait: 320x480px
- Landscape: 480x320px
- HDPI:
- Portrait: 480x800px
- Landscape: 800x480px
- XHDPI:
- Portrait: 720px1280px
- Landscape: 1280x720px
- XXHDPI:
- Portrait: 960px1600px
- Landscape: 1600x960px
- XXXHDPI:
- Portrait: 1280px1920px
- Landscape: 1920x1280px
Use images of above size for making your splash screen responsive among all the mobile and tablet devices.
Copy and paste following code in MainActivity.java
2 4 6 | import android.os.Handler; import android.os.Bundle; publicclassMainActivityextendsAppCompatActivity{ |
2 4 6 8 10 12 14 16 18 20 | privatefinalintSPLASH_DISPLAY_LENGTH=2000;//splash screen will be shown for 2 seconds /** Called when the activity is first created. */ publicvoidonCreate(Bundle icicle){ setContentView(R.layout.activity_main); newHandler().postDelayed(newRunnable(){ publicvoidrun(){ Intent mainIntent=newIntent(MainActivity.this,WelcomeActivity.class); finish(); },SPLASH_DISPLAY_LENGTH); } |
Introduction of HANDLER Class
The handler class lets you process and send message to other threads, which contain data, and runnable objects that belonging to a thread.
A handler will let you execute message objects and runnable objects at a specified time in the future.
Each instance of a handler will belong to a single thread only when declared.
Runnable objects are those objects that contain commands that will be executed to obtain results in your program.
To explain it to you plainly, a handler be used to execute a thread.
It will also allow various threads that make up a program to communicate with each other to prevent conflicts.
Explanation of MainActivity
We have used Handler class of JAVA to implement logic of Splash Screen.
- A handler has a method called run().
- In this run() method, you can write your required source code or give some instruction to your app.
Here in this example, I have tell my app to open WelcomeActivity.
- Now with the help of Handler, you can delayed the execution of the code written in run() method.
- You can give time duration in mili seconds to delay the execution of run() method.
In above example, I have taken 2000 mili seconds as delay.
I have used integer variable for this (SPLASH_DISPLAY_LENGTH).
- Right now value of SPLASH_DISPLAY_LENGTH is 2000 milliseconds, which is equals to 2 seconds. You can change this time duration as per your requirements. (Increase this value to shown splash for more time otherwise decrease it.)
- finish() method is written after starting a new activity. Splash screen is shown only at the opening of the app and when the user presses the back button to exit the app, splash screen should not be shown at that time.
- For this purpose, finish() method will help us. It will remove the splash screen activity from the backstack so when the user presses back button, he will directly left the app.
Second Method
You can implement the splash screen with Thread class also.
Sample source code for using Thread is as the below source code
2 4 6 8 10 12 14 16 18 20 22 | @Override try{ while(_active&&(waited<SPLASH_DISPLAY_LENGTH)){ if(_active){ } }catch(Exceptione){ }finally{ startActivity(newIntent(SplashScreen.this, finish(); }; splashTread.start(); |
- we are implementing a while() method in a thread.
- I have declared one integer variable called waited. Value of waited is zero at the starting.
- Value of waited is increased by 100 in the every iteration of the while loop.
- when the value of waited variable is greater than SPLASH_DISPLAY_LENGTH , finally() method is called by the compiler.
- In the finally() method, first activity of the android app is called.
To make splash screen with thread, replace the above code with the following code in our existing example
2 4 6 8 | @Override Intent mainIntent=newIntent(MainActivity.this,WelcomeActivity.class); finish(); },SPLASH_DISPLAY_LENGTH); |
After making this changes you will be able to show the splash screen using thread.
If you want some animation and cool effects in your splash screen, then visit following tutorial.
Related link: Other ways to implement splash screen.
How to get exact Android example while searching in Google
When you are learning new concepts in android app development, what do you do first? I guess you try to find that feature in google.
Now many times it happens that you enter search query for specific purpose but google gives you something else or may be it returned older tutorials with eclipse(which is already deprecated for android development) instead of android studio.
If you want to overcome these problems then visit below link, it will show you some techniques to solve these problems, which will save your lot of time and hard work as a result.
Do consider to share our tutorials and examples with your friend and colleagues via social media.
Cheers and happy coding!
Download Code For Android Splash Screen
[sociallocker]
Download Demo
[/sociallocker]
Download Demo
[/sociallocker]