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

17,275 views

Published on

A tutorial to show you how to add a splash screen to your Android application along with a timer and using some implemented functions.

Published in: Education, Technology
7 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
17,275
On SlideShare
0
From Embeds
0
Number of Embeds
37
Actions
Shares
0
Downloads
283
Comments
7
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. Android Application Tutorial How to add a splash screen with a timer Instructed on: 02-Mar-2012 | Tutorial: #06 6  By : Yasmine Sherif Mahmoud Tutorial Code: APS-06-2012All Copy Rights Saved to the 7th Students’ Conference on Communication and Information Based in the Faculty of Computersand Information Cairo University – Egypt 2011/2012 www.scci-cu.com
  2. 2. • 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:
  3. 3. I added the new picture that I want to use as a splash screen inmy drawable file.You can add a new picture as we have learned before in theprevious tutorials.
  4. 4. Here is the new picture.Do not forget to clean your project soyou can be able to see the picture.
  5. 5. Right Click on layout
  6. 6. We will delete this part of codeOpen the .Java file
  7. 7. Type R. and itwill give youthese options,Choose layout
  8. 8. After choosing thelayout , type . thenit will give you theseoptions.Choosesplash_screen
  9. 9. This is how you reference a your .xml file
  10. 10. • 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:
  11. 11. Right Click on yourproject
  12. 12. This is how it going to look like.We will have to add some code here to accessthe main.xml file
  13. 13. 2-Copy this line1-Open the old .Java file
  14. 14. 2- Paste the line you copied before here 3- Write extends Activity1- Back to the new .Java file
  15. 15. Right Click betweenthe parenthesisThis list will show up.
  16. 16. This will be auto generated as we used an alreadyimplemented class to use the function that willaccess the main.xml file
  17. 17. Write this line to finallyaccess the main.xml file
  18. 18. Go to the new splash_screen.xml file to add some code to it.
  19. 19. Open a tag < and write i the followinglist will appear choose ImageView
  20. 20. Inside the Image viewWrite android: and choose android:src from the listwhich will appear
  21. 21. Reference the picture youwant to use like that
  22. 22. Write android:la and chooseandroid:layout_width from the list which willappear
  23. 23. Write fill_parent sothat the picture will fillthe width of thescreen.
  24. 24. Write android:la and chooseandroid:layout_height from the list which willappear
  25. 25. This is how the code is going tolook like
  26. 26. When closing any filedon’t forget to save thechanged you have made.
  27. 27. • Now according the application life cycle (Shown next slide), we have to add all the functions that the application carry out.
  28. 28. • So now we are going to add all these functions in our code:
  29. 29. Open your old .Java file
  30. 30. Right Click in the bodyof the class and this listwill appear
  31. 31. This is where you are going to choose allthe functions that are found in theapplication life cycle.
  32. 32. This is how they going to look likeafter over riding them.
  33. 33. • After that we have to create the timer:
  34. 34. Write this line under herePut a semi colon after this parenthesis
  35. 35. Write thiscode
  36. 36. Write the followingcode inside this class
  37. 37. It’s a while loop that operates the timerWrite this line after the while loop but inside the trybody. Copy your package name.CLEARSCREEN in the brackets after Intent(“ ”)
  38. 38. You will have in error in the word Intentwhich can be fixed by using this:
  39. 39. Add this code afterthe try body
  40. 40. Add this line after the thread body
  41. 41. You will have an errorhere which can behandled by adding a catchto the try
  42. 42. This will be autogenerated, choosethe first option.
  43. 43. 2-Copy the shaded part1- Go to the Manifest.xml file
  44. 44. Paste it under itself
  45. 45. Change the android:name to.Mymain (the new .java fileyou created before)
  46. 46. Change the name to “yourpackagename.CLEARSCREEN”
  47. 47. Change it to .DEFAULT
  48. 48. The code after themodifications.
  49. 49. • Save and Run.
  50. 50. Splash screensuccessfully appeared 
  51. 51. • After 5 seconds , this screen will disappear and the next screen will be shown.
  52. 52. Yasmine Sherif EL-Adly @YasmineSherif91+Yasmine Sherif EL-Adly

×