B A J I H S: Egin Ndroid Ourney N OUR
B A J I H S: Egin Ndroid Ourney N OUR
IN HOURS
CS425 / CSE 424 / ECE 428 [Fall 2009]
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)
MOBILE OS
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.
Linux OS kernel
Java programming
Open source libraries: SQLite, WebKit, OpenGL
WHY ANDROID
A simple and powerful SDK
No licensing, distribution, or development fees
Development over many platform
Linux, Mac OS, windows
Excellent documentation
Thriving developer community
For us
Java-based, easy to import 3rd party Java library
Funding (40+ G1 phones)
Prize (amazon’s kindle)
Job opportunity
ANDROID SDK FEATURE
GSM, EDGE, and 3G networks, WiFi, Bluetooth
API Support for Bluetoothe, WiFi Ad hoc mode
Libraries
Media, SQLite, WebKit, SSL
Hardware control:
Accelerometer, compass, microphone, camera, GPS
touch screen, power
M1
A1: telnet + redir (MP1 doc)
Underlying
Infrastructure-based
WiFi /TCP/IP Network
Peer Peer
MP1 PROJECT STRUCTURE
Intent Activity
Content Providers
share data between applications
View Activity Intent Service Thread Resource
VIEW
screen.xml
Layout of visual interface <?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”http://schemas.android.com
/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
Java Code android:layout_height=”fill_parent”>
<TextView
Initialize android:id=”@+id/myTextView”
@Override android:layout_width=”fill_parent”
public void onCreate(Bundle icicle) { android:layout_height=”wrap_content”
super.onCreate(icicle); android:text=”Hello World, HelloWorld”
setContentView(R.layout.screen); />
} </LinearLayout>
Access
TextView myTextView =
(TextView)findViewById(R.id.myTextView);
View Activity Intent Service Thread Resource
VIEW COMPONENT
Widget Toolbox
TextView, EditText,Button, Form, TimePicker…
ListView (PeerList)
Update list by arrays
ArrayAdapter
myListView.setAdapter
Layout
Positions of controls
LinearLayout, Relativelayout
http://developer.android.com/guide/tutorials/views/index.html
Menu
Exit app
View Activity Intent Service Thread Resource
ACTIVITY
Foreground Activity: suspended when invisible
Visual, interactive Registration
Ex: Game, Map Peer List
Messaging
Background Service: Little interaction
Ex: Hardware, power management
Network
Operation
Management
Intermittent Activity
Notification, service
Expects some interactivity but does most of its work
in the background.
View Activity Intent Service Thread Resource
registerButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {….}}
myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
{
…
return true;
}
return false;
}});}
View Activity Intent Service Thread Resource
Subactivity: feedback
Child: use intent as feedback, setResult
Parent: onActivityResult
startActivityForResult
INTENT (CNTD.)
Manifest.xml
Broadcast <activity …>
<intent-filter>
announce application events <action
android:name=”com.paad.earthquake.inten
system-wide t.action.SHOW_DAMAGE”>
</action>
sendBroadcast <category
android:name=”android.intent.category.DE
MyBroadcastReceiver extends FAULT”/>
<category
BroadcastReceiver android:name=”android.intent.category.AL
TERNATIVE_SELECTED”/>
registerReceiver (in java / in xml) <data
android:mimeType=”vnd.earthquake.cursor
.item/*”/>
</intent-filter>
Intent Filter </activity>
Select a peer
Send Intent
PeerList Messaging
View Activity Intent Service Thread Resource
WORKING IN BACKGROUND
Services
NO GUI, higher priority than inactive Activities
Usage:
responding to events, polling for data, updating Content
Providers.
However, all in the main thread
Background threads
View Activity Intent Service Thread Resource
SERVICE
Service class
public class MyService extends Service
public void onStart() {…}
Manifest.xml
<service android:enabled=”true”
android:name=”.MyService”></service>
Control
startService
stopService
Communication
Bind service with activity: use public method and
properties
Intent
THREADING
Being Responsive (1sec)
Respond to any user action within 5 seconds.
A Broadcast Receiver must return within 10
seconds.
What to thread?
Network, file IO, Complex processing
How?
New Thread
Synchronize threads
Handler.post()
MP1 THREADING STRUCTURE
Is it enough?
Server
Server
Socket
Server
Socket
Socket
GUI Network Spawn
Acitivty Service
Thread
PERIODICAL REGISTER WITH SERVER
Every 15 seconds
Timer
Broadcast Receivers
exclusively used to update UI
DECLARATION OF APP – MANIFEST.XML
Service
<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1“ android:versionName="1.0“
package="com.uiuc.cs425">
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:debuggable="true">
Activity (intent-filter)
< android:name=".services.IMService" />
<activity android:name=".Register">
< >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category. />
</intent-filter>
</activity>
<activity android:name=".PeerList">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category. " />
</intent-filter>
</activity>
<activity android:name=".Messaging">
…
</activity>
Permission </application>
…
Don’t forget. Otherwise, <uses-permission android:name="android.permission. />
your socket programming <uses-permission
won’t run android:name="android.permission.
</manifest>
" />
View Activity Intent Service Thread Resource
EXTERNAL RESOURCES
values/
String, color, array, dimension, style theme
drawables/
Image
layout/
screen.xml
DEBUG
System.err.println()
Package - android.util.Log
View results
Logcat
Eclipse IDE
DEBUG ON DEVICE
On device
Debug mode
On desktop
Connect your G1 with your PC
When it asks for driver location choose
For windows, android-sdk-windows-1.5_r3\usb_driver\x86\
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
Reference: [http://www.anddev.org/debugging-
installing_apps_on_the_g1_windows_driver-
t3236.html]
INSTALL PACKAGE TO ANDROID PHONES
Compile the apk packages in Eclipse
Export signed application package
P3: integration
DEMO
DALVIK DEBUG MONITORING SERVICE
ANDROID DEBUG BRIDGE (ADB)