I wanted to make my app look more professional, so I decided that I wanted to make a splash screen.
How would I create it and then implement it?
I wanted to make my app look more professional, so I decided that I wanted to make a splash screen.
How would I create it and then implement it?
you will not use a layout file. Instead, specify your splash screen’s background as the activity’s theme background. To do this, first create an XML drawable in res/drawable.
Note: all code below is available GitHub Link
Here, I’ve set up a background color and an image.
Next, you will set this as your splash activity’s background in the theme. Navigate to your styles.xml file and add a new theme for your splash activity:
In your new SplashTheme, set the window background attribute to your XML drawable. Configure this as your splash activity’s theme in your AndroidManifest.xml:
Finally, your SplashActivity class should just forward you along to your main activity:
Notice that you don’t even set up a view for this SplashActivity. The view comes from the theme. When you set up the UI for your splash activity in the theme, it is available immediately.
If you did have a layout file for your splash activity, that layout file would be visible to the user only after your app has been fully initialized, which is too late. You want the splash to be displayed only in that small amount of time before the app is initialized.
Though there are good answers, I will show the google recommended way:
1)First create a
Theme
for splash screen: you have a theme calledsplashscreenTheme
, your launcher theme would be:Note:
android:windowBackground
already sets your splashscreen image noneed to do this in UI again.
you can also use color here instead of a drawable.
2)Set the theme to manifest of splashscreenActivity
3)make sure you launch_screen
drawable
is not indrawable
folder if your image is not small.It will result in faster launch screen start and save you from the black screen
It also avoids extra overdraw
Sometime user open the
SplashActivity
and quit immediately but the app still go toMainActivity
afterSPLASH_SCREEN_DISPLAY_LENGTH
.For prevent it: In
SplashActivity
you should check theSplashActivity
is finishing or not before move toMainActivity
Hope this help
A Splash Screnn, by default, does not automatically make your Application look more professional. A professionally designed Splash Screen has a possibility of making your Application look more professional, but if you do not know how to write one then how professional will the rest of your Application actually be.
About the only reason (excuse) to have a Splash Screen is because you are doing a massive amount of Calculations or are waiting for GPS/WiFi to startup because your Application relies on that prior to it starting. Without the result of those Calculations or access to GPS/WiFi (etc.) your Application is dead in the water, thus you feel you need a Splash Screen, and MUST block the view of the Screen for any other running Programs (including the Background).
Such a Splash Screen ought to look like your Full Screen Application to give the impression that it has already initialized, then after the lengthy calculations are completed the final details could be filled in (the Image tweaked). The chance of that being the case or that it is the only way the Program could be designed is mighty small.
It would be better to allow the User (and the rest of the OS) to do something else while they wait rather than design your Program to be dependant on something that will take a while (when the duration of the wait is uncertain).
There are Icons on your Phone already that say that GPS/WiFi is starting. The time or space taken up by the Splash Screen could be spent loading pre-calculations or actually doing the Calculations. See the first Link below for the problems you create and what must be considered.
If you absolutely must wait for these Calculations or GPS/WiFi it would be best to simply let the Application start and have a pop-up that says that it is necessary to wait for the Calculations (a TEXTUAL "Initializing" Message is fine). The wait for GPS/WiFi is expected (if they were not enabled in another Program already) so announcing their wait times are unnecessary.
Remember that when the Splash Screen starts your Program IS actually running already, all you are doing is delaying the use of your Program and hogging the CPU/GPU to do something that most do not feel is necessary.
We had better really want to wait and see your Splash Screen every time we start your Program or WE will not feel it is very professionally written. Making the Splash Screen FULL Screen and a duplicate of the actual Program's Screen (so we think it is initialized when in fact it has not) MIGHT accomplish your goal (of making your Program look more professional) but I would not bet much on that.
Why not to do it: http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/
How to do it: https://encrypted.google.com/search?q=Android+splash+screen+source
So there is a good reason not to do it but IF you are certain that somehow your situation falls outside those examples then the means to do it is given above. Be certain that it really does make your Application look more professional or you have defeated the only reason you gave for doing this.
It is like a YouTube Channel that starts every Video with a lengthy Graphic Intro (and Outro) or feels the need to tell a Joke or explain what happened during the past week (when it is not a Comedy or LifeStyles Channel). Just show the show ! (Just run the Program).
After Android Marshmallow, other Productive use of Splash screen I come to think of is requesting necessary
Android Permissions
in your app's splash screen.it seems like most apps handle permission request this way.
Dialogs make bad UIX and they break the main flow and make you decide on runtime and truth is most users might not even care if your app want to write something on SD card. Some of them might not even understand what we are trying to convey until we translate it in plain english.
Requesting permissions at one time make less number of "if else" before every operation and make your code looks clutter free.
This is a example of how you can ask for permissions in your splash activity for device running Android OS 23+ .
If all permissions are granted OR already granted OR app is running on Pre Marshmallow THEN just go and display main contents with little delay of half second so that user can appreciate effort we had put in reading this question and trying to give our best.