Friday, June 21, 2013

Android 1: Lesson 8

Android 1: Lesson 8: Logo and Start up music Java


INTRODUCTION
In this lesson you will be completeling the Java for the Logo and Start up music, and finally exporting your app
LESSON OBJECTIVES
By the end of this lesson, you will be able to:
1. Java for Logo
2. Java for music
3. Exporting
LEARNING SEQUENCE



Required Reading
Read the following:
Introduction To Development Environment
·        Eclipse
·        Android
·        Considerations for beginning programming.
Resources
View the following:
1.      Eclipse
2.     Android Development
Assignments
Java
  1. After the ‘onCreate(Bundle’ you’ll see ‘savedInstanceState’ You can change this to anything you’d like. Just make sure that you change the ‘super.onCreate’ to the same thing. It is renaming the variable
  2. Hit enter and type out ‘setContentView(R.layout.background);’ make sure ‘background’ is changed to whatever you name your xml in your layout.
  3. Now we’ll need to go into the ‘AndroidManifest.xml’. This is the god of the app. It tells the app what to start first, and how to start it. The Manifest is below the ‘res’ folder.
  4. In the AndroidManifest.xml, you’ll see a lot of code. Highlight the ‘activity’ and copy it and paste it right below. Java likes it if the first activity is the one that starts first, so the Logo class.
  5. Move your cursor to the ‘android:name’ and change ‘MainActivity’ to the name of the Logo class. Make sure that the capitalization is correct.
  6. Move down to the MainActivity activity and change the ‘LAUNCHER’ to  ‘DEFAULT’
  7. Now go back to the java and type ‘ourSong = MediaPlayer.create(yyy.this, R.raw.xxx);’ yyy should be whatever the Java is called, and xxx should be whatever the name of your song is in your raw folder.
  8. Hit enter and type ‘ourSong.start();’
  9. Hit enter and type ‘Thread timer = new Thread(){‘
  10. Hit enter and type ‘public void run(){‘
  11. Hit enter and type ‘try{‘
  12. The ourSong java is telling the app that it will be playing music, along with the Mediaplayer. The thread timer is telling the app that it will only be for a certain amount of time, and that is going to be defined in the try section. The public void is an open class.
  13. After ‘try{‘ hit enter and type ‘sleep(5000);’ this is telling the app to kill the music and the background after 5 seconds (5000 milliseconds).
  14. Hit enter again and type ‘} catch (InterruptedException e){‘ enter ‘e.printStackTrace();’
    These are telling the app to check to see if the Java fully stopped, and if not, to stop it.  
  15. Enter ‘}finally{‘ enter ‘Intent openStartingPoint = new Intent(“xxx.MainActivity”);’ xxx should be your class home, where all the java is. This piece of code tells the app what to start after the music and background finish.
  16. Close off that piece of code using ‘;’, there usually is an error or two with closing, sometimes following what the software says is the right way to do it, sometimes not.
  17. Enter ‘timer.start();’
  18. Close that off with ‘}’ under it. Hit enter again and right click. Go to ‘source’ and then to ‘override’ again. This time select ‘onPause’ and hit ok.
Exporting
  1. Ok. Now we can finally export. Make sure there are no errors throughout your app, if there are, the app most likely will crash when you try to start it. Make sure everything is closed with either ; or }
  2. Right click on your app, go down to ‘Android Tools’ then ‘Export Signed Application Package’
  3. Choose the project and hit next
  4. Click ‘Create new keystore’ choose where you want to save the app. And make a password. Hit next.
  5. Fill in an Alias, this will be what shows up on the market place, if you decide to put it on there. Pick another password. pick a ‘Validity’ which will be up to 1000 years. And fill in at least one field below. Hit next
  6. Choose where you want to save the .apk file, and there you go. You have exported. Just move the .apk file and put it on your phone and install it using any file finder app.

No comments:

Post a Comment