Top Banner
6 Android Application Tutorial How to add a splash screen with a timer All Copy Rights Saved to the 7 th Students’ Conference on Communication and Information Based in the Faculty of Computers and Information Cairo University – Egypt 2011/2012 www.scci-cu.com Tutorial Code: APS-06-2012 Instructed on: 02-Mar-2012 | Tutorial: #06 By : Yasmine Sherif Mahmoud
65

Android application (how to add a splash screen with timer) tutorial #4

Dec 06, 2014

Download

Education

A tutorial to show you how to add a splash screen to your Android application along with a timer and using some implemented functions.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Android application (how to add a splash screen with timer) tutorial #4

6

Android Application TutorialHow to add a splash screen with a timer

All Copy Rights Saved to the 7th Students’ Conference on Communication and Information Based in the Faculty of Computers and Information Cairo University – Egypt 2011/2012 www.scci-cu.com

Tutorial Code: APS-06-2012

Instructed on: 02-Mar-2012 | Tutorial: #06

By : Yasmine Sherif Mahmoud

Page 2: Android application (how to add a splash screen with timer) tutorial #4

• We will continue on our last project to add a splash screen with a timer to it.

• A splash screen is the first screen you see when you open the application.

• It disappears after an interval of time.• Open your last project and follow these steps:

Page 3: Android application (how to add a splash screen with timer) tutorial #4

I added the new picture that I want to use as a splash screen in my drawable file.You can add a new picture as we have learned before in the previous tutorials.

Page 4: Android application (how to add a splash screen with timer) tutorial #4

Here is the new picture.Do not forget to clean your project so you can be able to see the picture.

Page 5: Android application (how to add a splash screen with timer) tutorial #4

Right Click on layout

Page 6: Android application (how to add a splash screen with timer) tutorial #4
Page 7: Android application (how to add a splash screen with timer) tutorial #4
Page 8: Android application (how to add a splash screen with timer) tutorial #4

We will delete this part of code

Open the .Java file

Page 9: Android application (how to add a splash screen with timer) tutorial #4

Type R. and it will give you these options,Choose layout

Page 10: Android application (how to add a splash screen with timer) tutorial #4

After choosing the layout , type . then it will give you these options.Choose splash_screen

Page 11: Android application (how to add a splash screen with timer) tutorial #4

This is how you reference a your .xml file

Page 12: Android application (how to add a splash screen with timer) tutorial #4

• We are now accessing the Splash screen.xml but we can’t access the main.xml file anymore so we will have to create another .java file to access the main.xml file again at the same time of accessing the splash screen.xml file.

• Steps:

Page 13: Android application (how to add a splash screen with timer) tutorial #4

Right Click on your project

Page 14: Android application (how to add a splash screen with timer) tutorial #4
Page 15: Android application (how to add a splash screen with timer) tutorial #4

This is how it going to look like.We will have to add some code here to access the main.xml file

Page 16: Android application (how to add a splash screen with timer) tutorial #4

1-Open the old .Java file

2-Copy this line

Page 17: Android application (how to add a splash screen with timer) tutorial #4

1- Back to the new .Java file

2- Paste the line you copied before here

3- Write extends Activity

Page 18: Android application (how to add a splash screen with timer) tutorial #4

Right Click between the parenthesis This list will show up.

Page 19: Android application (how to add a splash screen with timer) tutorial #4
Page 20: Android application (how to add a splash screen with timer) tutorial #4
Page 21: Android application (how to add a splash screen with timer) tutorial #4

This will be auto generated as we used an already implemented class to use the function that will access the main.xml file

Page 22: Android application (how to add a splash screen with timer) tutorial #4

Write this line to finally access the main.xml file

Page 23: Android application (how to add a splash screen with timer) tutorial #4

Go to the new splash_screen.xml file to add some code to it.

Page 24: Android application (how to add a splash screen with timer) tutorial #4

Open a tag < and write i the following list will appear choose ImageView

Page 25: Android application (how to add a splash screen with timer) tutorial #4

Inside the Image view Write android: and choose android:src from the list which will appear

Page 26: Android application (how to add a splash screen with timer) tutorial #4

Reference the picture you want to use like that

Page 27: Android application (how to add a splash screen with timer) tutorial #4

Write android:la and choose android:layout_width from the list which will appear

Page 28: Android application (how to add a splash screen with timer) tutorial #4

Write fill_parent so that the picture will fill the width of the screen.

Page 29: Android application (how to add a splash screen with timer) tutorial #4

Write android:la and choose android:layout_height from the list which will appear

Page 30: Android application (how to add a splash screen with timer) tutorial #4

This is how the code is going to look like

Page 31: Android application (how to add a splash screen with timer) tutorial #4

When closing any file don’t forget to save the changed you have made.

Page 32: Android application (how to add a splash screen with timer) tutorial #4

• Now according the application life cycle (Shown next slide), we have to add all the functions that the application carry out.

Page 33: Android application (how to add a splash screen with timer) tutorial #4
Page 34: Android application (how to add a splash screen with timer) tutorial #4

• So now we are going to add all these functions in our code:

Page 35: Android application (how to add a splash screen with timer) tutorial #4

Open your old .Java file

Page 36: Android application (how to add a splash screen with timer) tutorial #4

Right Click in the body of the class and this list will appear

Page 37: Android application (how to add a splash screen with timer) tutorial #4

This is where you are going to choose all the functions that are found in the application life cycle.

Page 38: Android application (how to add a splash screen with timer) tutorial #4
Page 39: Android application (how to add a splash screen with timer) tutorial #4
Page 40: Android application (how to add a splash screen with timer) tutorial #4
Page 41: Android application (how to add a splash screen with timer) tutorial #4
Page 42: Android application (how to add a splash screen with timer) tutorial #4

This is how they going to look like after over riding them.

Page 43: Android application (how to add a splash screen with timer) tutorial #4

• After that we have to create the timer:

Page 44: Android application (how to add a splash screen with timer) tutorial #4

Write this line under here

Put a semi colon after this parenthesis

Page 45: Android application (how to add a splash screen with timer) tutorial #4

Write this code

Page 46: Android application (how to add a splash screen with timer) tutorial #4

Write the following code inside this class

Page 47: Android application (how to add a splash screen with timer) tutorial #4

It’s a while loop that operates the timer

Write this line after the while loop but inside the try body.

Copy your package name.CLEARSCREEN in the brackets after Intent(“ ”)

Page 48: Android application (how to add a splash screen with timer) tutorial #4

You will have in error in the word Intent which can be fixed by using this:

Page 49: Android application (how to add a splash screen with timer) tutorial #4

Add this code after the try body

Page 50: Android application (how to add a splash screen with timer) tutorial #4

Add this line after the thread body

Page 51: Android application (how to add a splash screen with timer) tutorial #4

You will have an error here which can be handled by adding a catch to the try

Page 52: Android application (how to add a splash screen with timer) tutorial #4

This will be auto generated, choose the first option.

Page 53: Android application (how to add a splash screen with timer) tutorial #4

1- Go to the Manifest.xml file

2-Copy the shaded part

Page 54: Android application (how to add a splash screen with timer) tutorial #4

Paste it under itself

Page 55: Android application (how to add a splash screen with timer) tutorial #4

Change the android:name to .Mymain (the new .java file you created before)

Page 56: Android application (how to add a splash screen with timer) tutorial #4

Change the name to “your package name.CLEARSCREEN”

Page 57: Android application (how to add a splash screen with timer) tutorial #4

Change it to .DEFAULT

Page 58: Android application (how to add a splash screen with timer) tutorial #4

The code after the modifications.

Page 59: Android application (how to add a splash screen with timer) tutorial #4

• Save and Run.

Page 60: Android application (how to add a splash screen with timer) tutorial #4
Page 61: Android application (how to add a splash screen with timer) tutorial #4

Splash screen successfully appeared

Page 62: Android application (how to add a splash screen with timer) tutorial #4

• After 5 seconds , this screen will disappear and the next screen will be shown.

Page 63: Android application (how to add a splash screen with timer) tutorial #4
Page 64: Android application (how to add a splash screen with timer) tutorial #4
Page 65: Android application (how to add a splash screen with timer) tutorial #4

Yasmine Sherif EL-Adly

@YasmineSherif91

+Yasmine Sherif EL-Adly

Contact Me: