1 / 32

Programming the Android Platform

The Android Development Environment. Programming the Android Platform. Topics. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse IDE The Android emulator Debugging Android applications Other tools. Installation. See:

verlee
Download Presentation

Programming the Android Platform

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. The Android Development Environment Programming the Android Platform

  2. Topics • Getting started on the Android Platform • Installing required libraries • Programming Android using the Eclipse IDE • The Android emulator • Debugging Android applications • Other tools

  3. Installation • See: • developer.android.com/sdk/index.html#quickstart • Software to download & install • Java Development Kit (JDK) • Eclipse IDE • Android SDK starter package • Eclipse ADT plugin • Add Android platform & other comps to SDK

  4. Java • Download Java Development Kit • www.oracle.com/technetwork/java/javase/downloads/index.html

  5. Eclipse • Preferred IDE, but you can use others • Requires version 3.5 or higher • Eclipse Classic recommended • http://www.eclipse.org/downloads/

  6. Android SDK starter package • Core tools needed to get started • developer.android.com/sdk/ • Unpack files to a directory of your choice • By default: android-sdk-<machine-platform> • Add this directory to your path to use Android tools from the command line

  7. Eclipse ADT plugin • Download the ADT plugin • Use the Help -> Install New Software function • URL for Eclipse 3.5+ • https://dl-ssl.google.com/android/eclipse/ • In the Available Software dialog, select the checkbox next to Developer Tools and click Next • Configure plugin • Open preferences, click on “Android” and set the SDK location

  8. Add Components to SDK • Launch the Android SDK and AVD Manager • Select at least the latest platform (2.3)

  9. Create an Android Virtual Device • An Android Virtual Device (AVD) is a configuration of emulator options • An AVD includes: • A hardware profile • A platform • Other options • e.g., emulator skin, screen dimensions, SD card size • A storage area • Create using Android SDK and AVD Manager tool

  10. HelloAndroid • Start Eclipse • Create a new Android Project

  11. Hello Android • Project name: HelloAndroid • Application name: Hello, Android • Package name: course.examples • Create activity: HelloAndroid • Min SDK: 9

  12. Hello Android (cont.) package course.examples; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroidextends Activity { public void onCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); TextViewtv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } }

  13. The Android Emulator • Applications can run in an emulator • Advantages • Fast turnaround • Doesn’t require an actual phone • Uses faster CPU on emulation computer • Disadvantages • Some features unavailable • e.g., no support for bluetooth or USB connections • Performance & user experience can be misleading

  14. The Android Emulator • Emulates telephone calls & SMS messages % telnet localhost 5554 > sms send 5554 “This is a text message” • Will emulate typical speeds & latencies for different networks (e.g., edge, gprs, etc.) % telnet localhost 5554 > set speed gprs • Can interconnect multiple emulators % emulator -avd Android_2.2_primary % emulator -avd Android_2.2_secondary • In one dialer app, dial port num of other emulator

  15. The Android Emulator • Many more options • See: developer.android.com/guide/developing/tools/emulator.html

  16. Debugger

  17. Execution Tracing

  18. Execution Tracing • Can also add trace code into your application // start tracing to "/sdcard/calc.trace"    Debug.startMethodTracing("calc");        … // stop tracing    Debug.stopMethodTracing(); • Will need to set permissions (discussed later) <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE />

  19. TraceView • To view results after execution % adb pull /sdcard/calc.trace /tmp % traceview /tmp/calc

  20. TraceView

  21. Logcat • Log viewer • Android logs many events by default • Can use android.util.Log & android.os.Debug class for application-specific logging • View log entries with • % adblogcat • Or inside Eclipse • Window -> Show View -> Other -> Android -> LogCat

  22. Hierarchy Viewer • Visual representation of application UI % hierarchyviewer

  23. Layout inspector

  24. Pixel Perfect View

  25. Monkey & monkeyrunner • Sends psuedorandom events to applications • Can also script events with monkeyrunner API // send event to browswer % adb shell monkey -pcom.android.browser -v 500 // send events to all applications % adb shell monkey 500

  26. Android Unit Testing • Android-specific extensions to Junit • MoreAsserts • Additional result checking classes • ViewAsserts • Asserts about view layout • TouchUtils • Classes for generating touch events • Instrumentation • For monitoring application interaction with system

  27. Android Unit Testing (cont.) • Steps for testing Activity • Create an Android test project • Create one or more Android test classes • Add code to each Test class • Test code usually includes test methods for • App initialization • UI behavior & class functionality • Application lifecycle state management

  28. Android Unit Testing (cont.) • AndroidTestCase • Test case with access to Activity Context • ActivityUnitTestCase • isolated testing of a single activity • InstrumentationTestCase • Test case with access to system instrumentation & events • ActivityInstrumentationTestCase2 • functional testing of a single activity • Many other test case types • developer.android.com/guide/topics/testing/testing_android.html

  29. Android Unit Testing (cont.) • Junit Test flow • setup() • Put application in known state • run() • Create additional data • Execute method under test • Check result with Assert • tearDown() • Return to known state

  30. Android Unit Testing (cont.) • developer.android.com/resources/tutorials/testing/activity_test.html

  31. Running on a Device • Key steps • Declare your application as "debuggable" in your Android Manifest • Turn on "USB Debugging" on your device • Setup your system to detect your device • See: • developer.android.com/guide/developing/device.html

  32. Lab Assignment

More Related