P. 1


|Views: 27|Likes:

More info:

Published by: Bùi Minh Thảo Thảo on Sep 20, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less






CS425 / CSE 424 / ECE 428 [Fall 2009] Sept. 14, 2009 Ying Huang


Online development guide


Book resource

“Professional Android Application Development”, by Reto Meier, (Wrox, amazon link)  “Android A programmers guide”, by J.F. DiMarzio, (McGraw Hill, amazon link)  “Beginning.Android”, by Mark L. Murphy, (Apress, amazon link)  “Pro Android”, by Sayed Y. Hashimi, Satya Komatineni, (Apress, amazon link)

Symbian  iPhone  RIM's BlackBerry  Window mobile  Linux  Palm webOS  Android  ….

WHAT IS ANDROID?  Google  OHA (Open Handset Alliance)  The first truly open and comprehensive platform for mobile devices. all of the software to run a mobile phone but without the proprietary obstacles that have hindered mobile innovation. OpenGL  . WebKit. Linux OS kernel  Java programming  Open source libraries: SQLite.

WHY ANDROID A simple and powerful SDK  No licensing. or development fees  Development over many platform  Excellent documentation  Thriving developer community    Linux. windows For us  Java-based. Mac OS. distribution. easy to import 3rd party Java library  Funding (40+ G1 phones)  Prize (amazon’s kindle)  Job opportunity .

power . WiFi. SQLite. GPS  touch screen. Bluetooth   Libraries  API Support for Bluetoothe. map (Google API) Accelerometer. compass. camera. SSL  Hardware control:   Location-based service. WebKit. EDGE. microphone.ANDROID SDK FEATURE  GSM. WiFi Ad hoc mode Media. and 3G networks.

and run shell commands. install compiled application packages. Monitor and Control the Dalvik virtual machines Logcat (see logged msgs)   Traceview  Manage the state of an emulator instance or Android-powered device  Copy files.TOOLS  The Android Emulator       Dalvik Debug Monitoring Service (DDMS) Android Debug Bridge (ADB) Implementation of the Android virtual machine Test and debug your android applications. Graphical analysis tool for viewing the trace logs from your Android application  Debug your application and profile its performance   MkSDCard Creates an SDCard disk image .

RUN TWO NETWORKING EMULATORS IN A COMPUTER (UPDATED) .ADB  Q: run two networking emulators in a computer A using the public IP address of A. during debugging and demo? E1  A1: telnet + redir (MP1 doc) A2: adb forward    M1 E2  1) Port forward to connect Android from localhost 2) Use a proxy server which can listen on my_public_ip:15216 and forward the data to localhost:15216  abd –s emulator-5554 forward tcp:15216 tcp:15216 stcppipe localhost 15216 15216 .

MP1 Peer Registration Server G1 Phone (Peer) Underlying Infrastructure-based WiFi /TCP/IP Network Peer Peer .

MP1 PROJECT STRUCTURE Registration PeerList Messaging .

focused thing that the user can do. embedded inside of another activity  Ex: Registration.  Interaction with users: creating a window to place UI  full-screen windows. A single. Peerlist. Messaging GUI . floating windows.View Activity Intent Service Thread Resource ANDROID APPLICATION ARCHITECTURE  Views:   Activities  Building block for user interface components.

notification  Ex: new message arrives share data between applications .View Activity Intent Service Thread Resource ANDROID APPLICATION ARCHITECTURE  Services (Background)  Activity  Intent  Ex: Network Operation Intent Activity  Resource  Inter-communication among activities or services Externalization of strings and graphics  Notification   Content Providers  signaling users: Light. dialog. sound. icon.

layout.com /apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”fill_parent”> <TextView android:id=”@+id/myTextView” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:text=”Hello World.onCreate(icicle).android.screen). }  Access TextView myTextView = (TextView)findViewById(R.0” encoding=”utf-8”?> <LinearLayout xmlns:android=”http://schemas.id.View Activity Intent Service Thread Resource VIEW  Layout of visual interface screen.myTextView). setContentView(R. . HelloWorld” /> </LinearLayout>  Java Code  Initialize @Override public void onCreate(Bundle icicle) { super.xml <?xml version=”1.

Form.com/guide/tutorials/views/index.android.html Positions of controls  LinearLayout.setAdapter  http://developer. Relativelayout  Menu  Exit app . EditText.View Activity Intent Service Thread Resource VIEW COMPONENT  Widget   TextView. TimePicker… ListView (PeerList)    Toolbox Update list by arrays  Layout  ArrayAdapter myListView.Button.

service  Expects some interactivity but does most of its work in the background. Map  Registration Peer List Messaging Network Operation Management  Background Service: Little interaction  Ex: Hardware.View Activity Intent Service Thread Resource ACTIVITY  Foreground Activity: suspended when invisible Visual. power management  Intermittent Activity  Notification. interactive  Ex: Game. .

setOnKeyListener(new OnKeyListener() { public boolean onKey(View v.} .getAction() == KeyEvent.setOnClickListener(new OnClickListener() { public void onClick(View arg0) {…. }}).ACTION_DOWN) if (keyCode == KeyEvent.View Activity Intent Service Thread Resource USER INTERACTION EVENT    onKeyDown. KeyEvent event) { if (event. onKeyUp onTrackBallEvent onTouchEvent registerButton.KEYCODE_DPAD_CENTER) { … return true. } return false. int keyCode.}} myEditText.

Im: Intent intent = new Intent(Intent.putExtra(name.ACTION_DIAL.this. Explicit  Subactivity: feedback  Implicit: Android selects the best  startActivity(). property). data. Uri. MyOtherActivity. extra parameter  Child: use intent as feedback. setResult  Parent: onActivityResult  startActivityForResult intent.View Activity Intent Service Thread Resource APPLICATION AND COMPONENT GLUES  An intent is an abstract description of an operation to be performed.   Action. .parse(“tel:555-2368”)). Ex: Intent intent = new  Launch an activity  Intent(MyActivity.class).

xml <activity …> <intent-filter> <action android:name=”com.inten t.DE FAULT”/> <category android:name=”android.intent.category. and Broadcast Receivers as being capable of performing an action on a particular kind of data.earthquake.paad. Services.intent.AL TERNATIVE_SELECTED”/> <data android:mimeType=”vnd.category.action.View Activity Intent Service Thread Resource INTENT (CNTD.cursor . .earthquake.)  Broadcast  Manifest.SHOW_DAMAGE”> </action> <category android:name=”android.item/*”/> </intent-filter> </activity> announce application events system-wide  sendBroadcast  MyBroadcastReceiver extends BroadcastReceiver  registerReceiver (in java / in xml)  Intent Filter  Register Activities.

View Activity Intent Service Thread Resource INTENT FROM PEERLIST TO MESSAGING Select a peer Send Intent PeerList Messaging .

higher priority than inactive Activities  Usage:   However. polling for data. updating Content Providers. all in the main thread responding to events.  Background threads .View Activity Intent Service Thread Resource WORKING IN BACKGROUND  Services  NO GUI.

MyService”></service>  Manifest.View Activity Intent Service Thread Resource SERVICE  Service class   public class MyService extends Service public void onStart() {…} <service android:enabled=”true” android:name=”.xml   Control   startService stopService  Communication  Bind service with activity: use public method and properties  Intent .

post() .THREADING  Being Responsive (1sec)   Respond to any user action within 5 seconds. Complex processing New Thread  Synchronize threads  Handler.  What to thread?   How?  Network. A Broadcast Receiver must return within 10 seconds. file IO.

MP1 THREADING STRUCTURE  Is it enough? Server Server Socket Server Socket Socket GUI Acitivty Network Service Spawn Thread .

PERIODICAL REGISTER WITH SERVER  Every 15 seconds Timer  How to update PeerList on PeerList GUI?  Intent .

ACTIVITY LIFETIME  Android apps do not control their lifetime. lose focus) Stopped (invisible) – Inactive (kill. Active (Foreground) . or Broadcast Receivers  create Services and threads Broadcast Receivers exclusively used to update UI . exit) threads.Paused (FG. processes.

intent. </intent-filter> </activity> <activity android:name=".MAIN" /> <category android:name="android.action.category. <uses-permission android:name="android.XML  Service  Activity (intent-filter)  Permission  Don’t forget. </manifest> <?xml version="1.DECLARATION OF APP – MANIFEST.com/apk/res/android" android:versionCode="1“ android:versionName="1.permission.intent.services.intent.android. </intent-filter> </activity> <activity android:name=".PeerList"> <intent-filter> <action android:name="android.0“ package="com.IMService" /> <activity android:name=".category.intent.uiuc. Otherwise.permission.cs425"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> /> " /> /> " /> .Messaging"> … </activity> </application> … <uses-permission android:name="android.action.0" encoding="utf-8" ?> <manifest xmlns:android="http://schemas.MAIN" /> <category android:name="android. your socket programming won’t run < android:name=".Register"> < > <action android:name="android.

color.xml . array. style theme Image  layout/  screen. dimension.View Activity Intent Service Thread Resource EXTERNAL RESOURCES  values/   drawables/  String.

err.util.android.println()  Package .Log   View results  Logcat  Eclipse IDE .DEBUG System.

html] .org/debugginginstalling_apps_on_the_g1_windows_drivert3236. android-sdk-windows-1.5_r3\usb_driver\x86\ Reference: [http://www.anddev.DEBUG ON DEVICE  On device  Debug mode Connect your G1 with your PC When it asks for driver location choose   On desktop    You'll see sth like "HTC Dream Composite ADB Interface" on success  (Re)Start Eclipse  Your G1 should now be listed in the DDMS-Perspective under Device  For windows.

INSTALL PACKAGE TO ANDROID PHONES  Compile the apk packages in Eclipse  Export signed application package  adb install …apk  Error: uninstall .

activity. cmd-shift-o or ctrl-shift-o Start as early as possible   Possible task partition for a group P1: GUI. intent  P2: network service  P3: integration  .OTHER TIPS  Automatic imports of packages In Eclipse.




You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->