android services peter liu school of ict, seneca college

10
ANDROID SERVICES Peter Liu School of ICT, Seneca College

Upload: victoria-cain

Post on 27-Dec-2015

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: ANDROID SERVICES Peter Liu School of ICT, Seneca College

ANDROID SERVICESPeter Liu

School of ICT, Seneca College

Page 2: ANDROID SERVICES Peter Liu School of ICT, Seneca College

What is an Android Service?

• an Android application• runs in the background• without an user interface (i.e. UI screen)

• a piece of Android code that runs in the background

Page 3: ANDROID SERVICES Peter Liu School of ICT, Seneca College

Android System Services

• the Location Service• the LocationManager class

• the Alarm Service• the AlarmManager class

• more examples…• WiFi Service• Bluetooth Service• Sensor Service

• Programming with the APIs• the getSystemService( ) methods• the <something>Manager objects

Page 4: ANDROID SERVICES Peter Liu School of ICT, Seneca College

How To Program an Android Service?• Diagram• Three Examples• Two Student Projects @ Seneca• Resources

Page 5: ANDROID SERVICES Peter Liu School of ICT, Seneca College

How To Program an Android Service?• Example 1: SimpleService

• the life cycle of a service• Example 2: LittleIntentService

• the IntentService• long-running background jobs

• a worker thread vs the UI thread

• data communication between an activity and a service

Page 6: ANDROID SERVICES Peter Liu School of ICT, Seneca College

How To Program an Android Service?• Example 2

• data communication • use an Intent to pass the data from an activity to a

service

• broadcast work status from a service to an activity

• Should you use a thread or a service?• http://developer.android.com/guide/components/services.html

Page 7: ANDROID SERVICES Peter Liu School of ICT, Seneca College

How To Program an Android Service?• Example 3: MyService

• 2 forms of a service• started• bound (for data communication)

• use Intent for passing simple data• use method calls to pass complex data

Page 8: ANDROID SERVICES Peter Liu School of ICT, Seneca College

How To Program an Android Service?• Best Practices for Background Jobs

• http://developer.android.com/training/best-background.html

Page 9: ANDROID SERVICES Peter Liu School of ICT, Seneca College

Two Student Projects @ Seneca• Natesh’s team (Android Game)• Edward Hanna at CDOT (MMDI)

Page 10: ANDROID SERVICES Peter Liu School of ICT, Seneca College

Resources

• the course wiki•developer.android.com

• http://developer.android.com/guide/components/services.html