1 / 47

Android Programming

Android Programming. Beomjoo Seo (seobj@comp.nus.edu.sg) Sep., 12 CS5248 Fall 2012. Contents. Installation Example by a sample app, “Hello, CS5284” Create an Android Project Building and Running Debugging General Topics Fundamental Components

mavis
Download Presentation

Android Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Programming BeomjooSeo (seobj@comp.nus.edu.sg) Sep., 12 CS5248 Fall 2012

  2. Contents • Installation • Example by a sample app, “Hello, CS5284” • 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, MP4Parser • Sample Application http://developer.android.com/guide/index.html

  3. Installation Procedure http://developer.android.com/index.html • Install JDK 5 or JDK 6 • Install Eclipse IDE • Eclipse 3.5 or above • 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 Eclipse IDE for Java (EE) Developers

  4. Install SDK Packages • From Android SDK and AVD Manager Via console OR via eclipse

  5. SDK Version Mapping Convention • Android 4.0.3 Platform • SDK Tools, Revision 20 • API Level: 15

  6. Eclipse ADT Plugin Configuration At Windows > Preferences > Android Specify Android SDK location Increase ADT connection time out

  7. Creating a Sample App,“Hello, CS5248”

  8. Eclipse > New > Android Project

  9. Main Activity Class

  10. Graphical Layout Editor Update ADT plugin !!!

  11. XML Layout File

  12. Value Resources - Strings.xml

  13. R.java

  14. The Manifest file

  15. Default.properties

  16. Building App

  17. Building Process Running

  18. No Android Device ? Install USB Driver !!!

  19. USB Driver Installation • Install OEM USB Driver from ASUS website. • http://support.asus.com/download/ and search by Transformer • Update Driver Software from Device Manager • Locate USB Driver folder • Enable USB Debugging at Transformer Update Driver software

  20. Enabling USB debugging OR

  21. After Successful USB Driver Installation <sdk>/tools/ddms.bat OR

  22. Running Sample App.

  23. Sample Hello World Code

  24. Editing Sample Code Add id to main.xml “@+id/helloId” Edit HelloWorldActivity.java BE PATIENT Since Eclipse may not be responsive for a long time !!!

  25. Let’s Debug the code

  26. A Sample Code

  27. App Failure

  28. Always, Look at DDMS !!!

  29. Correction

  30. Debugging via Dalvik Debug Monitor (ddms) Log.e("Hello, World", "Hello, BJ");

  31. Now, everything is ready

  32. 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

  33. Activity 1 • Activity Lifecycle • Implement Lifecycle Callbacks

  34. Activity 2 • Hierarchical View Architecture • ViewGroup (Layout) • View • View • ViewGroup (Layout) • View • View • … • View • ViewGroup • … • Declare Activity in the manifest

  35. Activity 3 • Start an Activity • Start an Activity for a Result • Caller Activity • Callee Activity • finish • Activities and Stack

  36. UI – Declaring Layout • Initiated when called setContentView() on onCreate() • Use Visual Layout Editor for initial layout design. • Edit XML file extensively. wrap_content or fill_parent

  37. 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 callback At res/menu/game_menu.xml inflate

  38. UI – Handling UI Events • onClick, onLongClick, onKey, onTouch, …

  39. 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

  40. Use AsyncTask, Instead

  41. Misc - Media Recorder • Modify CameraPreview to see the video during recording.

  42. Misc - HTTP Post • Use HttpClient and HttpPost. • Use “multi-part/form-data” to encapsulate segment. • Do not allocate memory excessively .

  43. Misc - Integration with MP4Parser • 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 getResourceAsStream(“isoparser-default.properties”) in PropertyBoxParserImpl to “/assets/isoparser-default.properties”.

  44. Misc - Connecting to NUS Wifi

  45. Misc – Permission Issue • Add following permissions to the manifest file.

  46. Sample Implementation MainActivity Option menu Context menu Record Upload Item Click Preview Item Click RecordActivity Upload Service Record Button Click PlayerActivity

  47. Final Comment: Use ApiDemo !!!

More Related