Splash Screen in Android with Network Activity

Whenever you launch an app, you would have seen Splash screen or Launcher screen or Startup screen coming up for first few seconds. This is used mainly for 2 purposes:

  • Branding
  • Downloading data from the internet or server.

If Splash screen is used for branding, then it will be displayed for a fixed interval of time, say for 3 seconds. If it is used for downloading data from the server, then the duration of displaying splash screen depends on the time taken for downloading the data.

Most of the apps which use the Internet will have Splash screen to download the data on startup. Let’s see how can we implement Splash screen in both ways:

  1. Displaying Splash screen for a particular interval of time.
  2. Displaying Splash screen while downloading data from the server.

Displaying Splash screen for a particular interval of time

1. Create a new Project in Android Studio with the name “Splash Screen Demo“.

2. Now create a new Blank Activity (File > New > Activity > Blank Activity). Let the activity name be SplashActivity.

3. Download splash.png and place it in the drawable folder of the project. This will be used as Splash screen background.

4. Now open strings.xml and add the string resources used in the Project:

5. In activity_splash.xml, add the splash image as background and have a TextView to display a welcome message as shown below. You can also place an image instead of text, representing your brand.

6. In AndroidManifest.xml,  make the newly created activity as Launcher Activity, so that splash screen appears on the launch of the application. Also, remove launcher intent filter from MainActivity. In order for the splash screen go full screen, add the theme “@android:style/Theme.Black.NoTitleBar.Fullscreen”:

7. Now change SplashActivity.java to the following:

You can change the value of SPLASH_TIME_OUT field in order to change the duration of the splash.

8. Now run the application on your Android device or emulator. Given below is a sample demo:

Splash Screen Demo

 

Download Source CodeDownload APK

Displaying Splash screen while downloading data from the server

1. Create a project in Android Studio with the name “Splash Screen with Network Activity“.

2. Repeat the steps 2-4 given above.

3. Open activity_splash.xml and add a ProgressBar in addition to the TextView. The progress bar is displayed while the data is being downloaded from the server.

4. In AndroidManifest.xml, add Internet permission:

5. Create a java class named HttpJsonParser and add the following code. This is used to download the JSON data from the server and parse it. We are reusing this class from one of my previous post: JSON Parsing in Android over HTTP.

6. Open activity_main.xml and the following code. We will be using the TextView to display the statistics data fetched from the server.

7. In SplashActivity class, create an AsyncTask for the network operation. On successful download of the data i.e., in the onPostExecute method, parse the data and pass it into the MainActivity. You can refer to the tutorial Passing Data Between Activities for understanding on how to launch a new activity and pass data to it.

8. Finally, open MainActivity and add code for displaying the statistics data.

9. Now run the application on your device. You can see the demonstration of the app below. You can also download the source code and the APK.

Splash Screen with Network Activity Demo

 

Download Source CodeDownload APK

If you have any doubts, then we can discuss them in the comments section. If you have liked this tutorial, please do follow us on Twitter and Facebook.

Stay Connected

No spam guarantee.

Abhishek

Abhishek

Abhishek loves coding. His favorite is Android Development. Apart from coding he loves traveling and reading.
Abhishek

Latest posts by Abhishek (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *