Android Programming Beomjoo Seo seobjcomp nus edu sg
Android Programming Beomjoo Seo (seobj@comp. nus. edu. sg) Sep. , 12 CS 5248 Fall 2012
Contents • Installation • Example by a sample app, “Hello, CS 5284” – Create an Android Project – Building and Running – Debugging • General Topics – Fundamental Components • Activity, Service, Content Providers, and Broadcast Receiver – – Activity, Intent UI : Layout, Menu Thread Misc: Media Recorder, HTTP Post, MP 4 Parser • Sample Application http: //developer. android. com/guide/index. htm l
Installation Procedure http: //developer. android. com/index. html • Install JDK 5 or JDK 6 • Install Eclipse IDE – Eclipse 3. 5 or above Eclipse IDE for Java (EE) Developers • Eclipse JDT plugin – Run Android SDK starter package – Install ADT plugin (ADT 20. 0. 3) • Eclipse > Help > Install New Software … -> Add – https: //dl-ssl. google. com/android/eclipse/ • Configure ADT plugin
Install SDK Packages • From Android SDK and AVD Manager Via console OR via eclipse
SDK Version Mapping Convention • Android 4. 0. 3 Platform – SDK Tools, Revision 20 – API Level: 15
Eclipse ADT Plugin Configuration At Windows Specify Android SDK location > Preferences > Android Increase ADT connection time out
Creating a Sample App, “Hello, CS 5248”
Eclipse > New > Android Project
Main Activity Class
Graphical Layout Editor Update ADT plugin !!!
XML Layout File
Value Resources - Strings. xml
R. java
The Manifest file
Default. properties
Building App
Building Process Running
No Android Device ? Install USB Driver !!!
USB Driver Installation 1. Install OEM USB Driver from ASUS website. http: //support. asus. com/download/ and search by Transformer 2. Update Driver Software from Device Manager Update Driver software 3. Locate USB Driver folder 4. Enable USB Debugging at Transformer
Enabling USB debugging OR
After Successful USB Driver Installation <sdk>/tools/ddms. bat OR
Running Sample App.
Sample Hello World Code
Editing Sample Code Add id to main. xml “@+id/hello. Id” Edit Hello. World. Activity. java BE PATIENT Since Eclipse may not be responsive for a long time !!!
Let’s Debug the code
A Sample Code
App Failure
Always, Look at DDMS !!!
Correction
Debugging via Dalvik Debug Monitor (ddms) Log. e("Hello, World", "Hello, BJ");
Now, everything is ready
Application Components • Android application –. apk : android package • Four Application Components – Activity • A single screen with a user interface – Service • A background processing unit with no user interface – Content Provider – Broadcast Receiver • Communication among components except Content Provider – Intent
Activity 1 • Activity Lifecycle • Implement Lifecycle Callbacks
Activity 2 • Hierarchical View Architecture – View. Group (Layout) • View. Group (Layout) – View – … • View. Group – … • Declare Activity in the manifest
Activity 3 • Start an Activity for a Result – Caller Activity – Callee Activity • finish • Activities and Stack
UI – Declaring Layout • Initiated when called set. Content. View() on on. Create() • Use Visual Layout Editor for initial layout design. • Edit XML file extensively. wrap_content or fill_parent
UI – Creating Menu • Menu Types – Options Menu • Appears when a user touches MENU button. – Context Menu – Submenu • How to – Specify menu items in a XML resource menu – Inflate a Menu Resource – Respond to user Action At res/menu/game_menu. xml inflate callback
UI – Handling UI Events • on. Click, on. Long. Click, on. Key, on. Touch, …
Thread • UI Thread – “Main” thread per application responsible for interacting with UI components. • “Application Not Responding” problem – If UI thread is blocked more than several seconds, ANR dialog appears. – Do not block the UI thread – Do not access UI components outside UI thread. modify
Use Async. Task, Instead
Misc - Media Recorder • Modify Camera. Preview to see the video during recording.
Misc - HTTP Post • Use Http. Client and Http. Post. • Use “multi-part/form-data” to encapsulate segment. • Do not allocate memory excessively.
Misc - Integration with MP 4 Parser • Adding a jar file – Create its jar file. – Add jar file to the app. • Build Path > Configure Build Path > Libraries > Add JARs. • If you include source files directly, – Put Isoparser-default. properties to assets folder – Change get. Resource. As. Stream(“isoparserdefault. properties”) in Property. Box. Parser. Impl to “/assets/isoparser-default. properties”.
Misc - Connecting to NUS Wifi
Misc – Permission Issue • Add following permissions to the manifest file.
Sample Implementation Main. Activity Option menu Context menu Record Upload Item Click Preview Item Click Record. Activity Upload Service Record Button Click Player. Activity
Final Comment: Use Api. Demo !!!
- Slides: 47