Programming Mobile Applications for Android Handheld systems, Part 1
Week 5 - Threads, AsyncTasks and Handlers, and Networking
Threads, AsyncTasks and Handlers
Provide notes on this course.
Networking
JSON format
XML format
DOM (complete reading of the document object model)
SAX (stream reading with callbacks) parsers.
PULL similar to SAX but the reading of the next element is controlled by the application.
Week 6 - User Notifications, BroadcastReceiver and Alarms
User Notifications
Provide notes on this course.
BroadcastReceiver class
BroadcastReceiver class
Wait for events, receive them and react to them
Broadcast receiver register for the type of events they are interested in.
Intent are broadcasted
onReceive() method called with received intent.
Registration
Static registration:
Dynamic registration
create IntentFilter object
create BroadcastReceiver
register BroadcastReceiver using registerReceiver()
call unRegisterReceiver()
Broadcast
Normal or ordered.
sticky or non-sticky.
With or without receiver permission.
debug details with: Intent.setFlag(FLAG_DEBUG_LOG_RESOLUTION)
adb dumpsys to get more info on broadcast receiver.
Processing
Event delivery:
BroadcastReceiver are only valid while in onReceive() method.
sendOrderedBroadcast()
abortBroadcast() ⇒ to stop a broadcast.
sendStickyBroadcast()
sendStickyOrderedBroadcast()
apps need BROADCAST_STICKY permission to broadcast these.
use isInitialStickyBroadcast() to check for cached sticky broadcast.
Alarms
Alarms
AlarmManager
getSystemService(ALARM_SERVICE)
set(type, triggerAtTime, PendingIntent);
setRepeating(type, triggerAtTime, interval, pendingIntent)
setInexactRepeating(…)
PendingIntent:
create with:
getActivity(…)
getBroadcast(…)
getService(…)
Graphics and animation
2D graphics
ImageView
Canvas
Complicated, more powerfull.
drawText(), drawPoints(), drawColor(), drawOval(), drawBitmap(), etc.
GenericView for less frequent drawning.
SurfaceView for frequent drawing.
Drawable class:
ShapeDrawable
PathShape
RectShape
OvalShape
BitmapDrawable
ColorDrawable
Touch and Gestures
MotionEvents
Action code
ACTION_DOWN
ACTION_POINTER_DOWN
ACTION_POINTER_UP
ACTION_MOVE
ACTION_UP
ACTION_CANCEL
getActionMasked()
getActionIndex()
getPointerId(index)
getPointerCount()
getX(pindex)
getY(pindex)
findPointerIndex(pid)
time of event
device
location
pressure
MultiTouch:
Touch Handling
View.onTouchEvent()
View.OnTouchListener
Audio, Images, Movies
Use camera