Download - Android App Development 20150528
Android App Development 5
28 May, 2015
Add a New Button LinearLayout (vertical)
Starting Another Activity Create the Second Activity goNextActivity() Method
Build an Intent Add a startActivity Method
Last Workshop
Adding an Image Adding Audio
Today’s Contents
Step 1 : Preparing an Image fileStep 2 : Adding <ImageView>
Adding an Image
Supported Image Formats BMP / JPG / PNG / GIF
Image Folder Put your image file into folder
res/drawable
Step 1 : Preparing an Image file
Adding an Image
image01.jpg (300 x 255)
Edit res/layout/activity_my.xml Add <ImageView> element
Step 2 : Adding <ImageView>
Adding an Image
res/drawable folder file extension can be omitted
Adding an Image
Adding Audio
SoundPool an Android library
specifically targeted for playing short audio clips
Supported Audio Formats wav / ogg
Adding Audio
sound01.wav
MediaPlayer for longer sound files or streams
Step 1 : Preparing an Audio fileStep 2 : Declaring VariablesStep 3 : Loading an Audio fileStep 4 : Playing an Audio fileStep 5 : Releasing SoundPool resources
Adding Audio
Add raw folder under res folder
Put your audio file into folder res/raw
Step 1 : Preparing an Audio file
Adding Audio
Edit MyActivity.java Declare 2 Variables in MyActivity class
Step 2 : Declaring VariablesAdding Audio
…
}
*To use SoundPool, import SoundPool class
Edit MyActivity.java Add onResume() method to MyActivity
class
Step 3 : Loading an Audio file
Adding Audio
res/raw folderfile extension can be omitted
system calls this method when the activity comes to the foreground
Edit MyActivity.java Add playAudio() method to MyActivity class
Edit res/layout/activity_my.xml Add onClick attribute to ImageView element
Step 4 : Playing an Audio fileAdding Audio
Edit MyActivity.java Add onPause() method to MyActivity
class
Step 5 : Releasing SoundPool resources
Adding Audio
system calls this method when another activity is started
Adding Audio
Wrap Up for Today
Adding an Image ImageView element
Adding Audio SoundPool
Follow the link and read the articles Android Activity Lifecycle
http://www.codelearn.org/android-tutorial/android-activity
Assignment
fin.
2 more workshops left.