android - sensor manager

Post on 10-Feb-2017

1.988 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Android –Sensor Manager

Yong Heui Cho @ Mokwon University

Some of slides are referred to:[1] Nitin Ramchandani, Android OS, slideshare.

2

Smart Device M2M

10. Arduino+Android - BT+IoTN11. Arduino - Pressure Sensor

12. Android – Sensor Message

13. BT+IoTN Project - Con-cept

3

Application

Application Structure

Activity

Context

OS

Resources

Service

lifecycle

4

Activity Lifecycle

5

Lifecycle Comparison

Run Terminate

onCreate() onDestroy()

onStart() onStop()

onResume() onPause()

onRestart() -

onRestoreInstanceState() onSaveInstanceState()

6

Summary of Lifecycle

7

Android vs. Windowstype Android Windows

CPU optimal fast

battery small power supply

memory mobile DRAMsmall

DRAMlarge

message handler message (Message) or action (String) message (int)

termination app lifecycle permanent

function call call & proceed call & wait or call & proceed

8

MVC Components

9

Android Msg Handler

• Message: containing a description and arbitrary data object

• Runnable: a command that can be executed• Handler: allows you to send and process

Message and Runnable • Looper: used to run a message loop for a thread

10

Concept of Multithread

11

Android Rules• Do not block the UI thread (or

main thread).• Do not access the Android UI

toolkit from outside the UI thread.

12

Event Listener• Interface to process specific

events

13

PhoneStateListner• Monitors changes in specific telephony

states on the device, including service state, signal strength, message waiting indicator (voicemail).

Activity

Context

PhoneStateListener

OS

TelephonyManager

listen()

14

Broadcast Receiver

• An Intent-based publish-subscribe mechanism.

• Great for listening system events such as SMS messages.

□ Courtesy to Everything of Android, slideshare.

15

BR vs. Listenertype BroadcastReceiver Listener

goal class for Intentsclass or interface for Intents & oth-

ers

message mostly global mes-sages

mostly specific messages

period discontinuous re-ception

frequent (or continu-ous) reception

construction static (manifest) or dynamic dynamic only

16

Android & Sensors

17

Sensor Manager• SensorManager

Context.getSystemService(SENSOR_SERVICE)

• Sensor SensorManager.getDefaultSensor(Sensor.TYPE_XXX)

• SensorManager.registerListener(SEL, Sensor, int samplingPeriodUs)

• SensorManager.unregisterListener(SEL)

18

SensorEventListener

19

Type of Sensors

top related