android programming beomjoo seo ([email protected]) sep., 12 cs5248 fall 2012

Download Android Programming Beomjoo Seo (seobj@comp.nus.edu.sg) Sep., 12 CS5248 Fall 2012

If you can't read please download the document

Upload: ada-evans

Post on 22-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

  • Slide 1
  • Android Programming Beomjoo Seo ([email protected]) Sep., 12 CS5248 Fall 2012
  • Slide 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
  • Slide 3
  • Installation Procedure 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 http://developer.android.com/index.html Eclipse IDE for Java (EE) Developers
  • Slide 4
  • Install SDK Packages From Android SDK and AVD Manager Via consoleORvia eclipse
  • Slide 5
  • SDK Version Mapping Convention Android 4.0.3 Platform SDK Tools, Revision 20 API Level: 15
  • Slide 6
  • Eclipse ADT Plugin Configuration Specify Android SDK locationIncrease ADT connection time out At Windows > Preferences > Android
  • Slide 7
  • Creating a Sample App, Hello, CS5248
  • Slide 8
  • Eclipse > New > Android Project
  • Slide 9
  • Main Activity Class
  • Slide 10
  • Graphical Layout Editor Update ADT plugin !!!
  • Slide 11
  • XML Layout File
  • Slide 12
  • Value Resources - Strings.xml
  • Slide 13
  • R.java
  • Slide 14
  • The Manifest file
  • Slide 15
  • Default.properties
  • Slide 16
  • Building App
  • Slide 17
  • Building Process Running
  • Slide 18
  • No Android Device ? Install USB Driver !!!
  • Slide 19
  • 1.Install OEM USB Driver from ASUS website. http://support.asus.com/download/http://support.asus.com/download/ and search by Transformer 2.Update Driver Software from Device Manager 3.Locate USB Driver folder 4.Enable USB Debugging at Transformer USB Driver Installation Update Driver software
  • Slide 20
  • Enabling USB debugging OR
  • Slide 21
  • After Successful USB Driver Installation /tools/ddms.bat OR
  • Slide 22
  • Running Sample App.
  • Slide 23
  • Sample Hello World Code
  • Slide 24
  • Editing Sample Code BE PATIENT Since Eclipse may not be responsive for a long time !!! Add id to main.xml Edit HelloWorldActivity.java @+id/helloId
  • Slide 25
  • Lets Debug the code
  • Slide 26
  • A Sample Code
  • Slide 27
  • App Failure
  • Slide 28
  • Always, Look at DDMS !!!
  • Slide 29
  • Correction
  • Slide 30
  • Debugging via Dalvik Debug Monitor (ddms) Log.e("Hello, World", "Hello, BJ");
  • Slide 31
  • Now, everything is ready
  • Slide 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
  • Slide 33
  • Activity 1 Activity Lifecycle Implement Lifecycle Callbacks
  • Slide 34
  • Activity 2 Hierarchical View Architecture ViewGroup (Layout) View ViewGroup (Layout) View View ViewGroup Declare Activity in the manifest
  • Slide 35
  • Activity 3 Start an Activity Start an Activity for a Result Caller Activity Callee Activity finish Activities and Stack
  • Slide 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
  • Slide 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 At res/menu/game_menu.xmlinflate callback
  • Slide 38
  • UI Handling UI Events onClick, onLongClick, onKey, onTouch,
  • Slide 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
  • Slide 40
  • Use AsyncTask, Instead
  • Slide 41
  • Misc - Media Recorder Modify CameraPreview to see the video during recording.
  • Slide 42
  • Misc - HTTP Post Use HttpClient and HttpPost. Use multi-part/form-data to encapsulate segment. Do not allocate memory excessively.
  • Slide 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.
  • Slide 44
  • Misc - Connecting to NUS Wifi
  • Slide 45
  • Misc Permission Issue Add following permissions to the manifest file.
  • Slide 46
  • Sample Implementation MainActivity RecordActivity Upload Service PlayerActivity Option menuContext menu Record Record Button Click Preview Item ClickUpload Item Click
  • Slide 47
  • Final Comment: Use ApiDemo !!!