Top Banner
Android Manchester Week 8 - Services & Notifications
38

Android Jam - Services & Notifications - Udacity Lesson 6

Jul 16, 2015

Download

Technology

Paul Blundell
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Android Jam - Services & Notifications - Udacity Lesson 6

Android ManchesterWeek 8 - Services & Notifications

Page 2: Android Jam - Services & Notifications - Udacity Lesson 6

Overview

● Retro○ Lesson 6 Services & Notifications

● Looking Forward○ The Final Project

● Stickers● Next retro 31st March (2 weeks!)● Next Tues 7-8pm SpacePortX

Page 3: Android Jam - Services & Notifications - Udacity Lesson 6

Energizer

Stand up and introduce yourself to somebody around you, you don’t know

Page 4: Android Jam - Services & Notifications - Udacity Lesson 6

Prime Directive

‘Regardless of where we are up to, we understand and truly believe that everyone did the best job he or she could, given his or her skills and abilities, the personal time available, and the situation at hand.’

Page 5: Android Jam - Services & Notifications - Udacity Lesson 6

Difficulty Check● Who completed the class?

● How long did it take?

● Hands up 1-10 difficulty of the lesson

● Any specific areas of the lesson that require particular focus?

Page 6: Android Jam - Services & Notifications - Udacity Lesson 6

Retro lesson 6 services & notifications

What we learnt last week● Services● Application priority● Alarms● Transferring data efficiently● SyncAdapters● Notifications

Page 7: Android Jam - Services & Notifications - Udacity Lesson 6

Services● Execute long running tasks that shouldn’t be interrupted● Have a lifecycle but no user interface● Declared in the AndroidManifest

Page 8: Android Jam - Services & Notifications - Udacity Lesson 6

Services● Run on the main thread - which means…..?

○ AsyncTasks, SyncAdapter, IntentService etc.● Typically override onStartCommand● No state methods such as onResume, onPause etc

Page 9: Android Jam - Services & Notifications - Udacity Lesson 6

Service Extras● startForeground(Notification notification);

○ increases priority○ shouldn’t be killed to clear resources

● IntentService (subclass) provides onHandleIntent which runs off the main thread○ Executes Intents sequentially○ Good for downloading

Page 10: Android Jam - Services & Notifications - Udacity Lesson 6

App Priority

● Apps running in the background have a responsibility to be good citizens!

● Async Task can be used to download files/play music but risk being deleted when the app is in the background

● Services allow us to deal with these use cases

Page 11: Android Jam - Services & Notifications - Udacity Lesson 6

App Priority

Page 12: Android Jam - Services & Notifications - Udacity Lesson 6

App Priority - the 3 laws

Page 13: Android Jam - Services & Notifications - Udacity Lesson 6

Test...

● Consider effect on user experience● Consider component - is it an

Activity or Service?● User interaction● And is it background/foreground?

3 Laws

1. Android will ensure a smooth UX2. Android will keep all activities and

services running unless they violate the 1st law

3. Android will keep background apps running unless they violate 1st or 2nd law

Page 14: Android Jam - Services & Notifications - Udacity Lesson 6

Efficiency

Clue: We’re aiming for less data, less often

Page 15: Android Jam - Services & Notifications - Udacity Lesson 6

Battery Drain

Page 16: Android Jam - Services & Notifications - Udacity Lesson 6

The cell radio

Efficiency is driven by hardware considerations

Page 17: Android Jam - Services & Notifications - Udacity Lesson 6

The cell radio analysed

V

blue - active data transfersred - radio in full poweryellow - lower power modeblack - idle

Page 18: Android Jam - Services & Notifications - Udacity Lesson 6

Efficiency

Page 19: Android Jam - Services & Notifications - Udacity Lesson 6

Interlude - making good apps great

Page 20: Android Jam - Services & Notifications - Udacity Lesson 6

Further WatchingGoogle I/O 2013 - Android Protips 3: Making Apps Work Like Magic

https://www.youtube.com/watch?v=GcNNx2zdXN4

Google I/O 2012 - Android Protips 2:Making Good Apps Great

https://www.youtube.com/watch?v=PwC1OlJo5VM

Google I/O 2011: Android Protips: Advanced Topics for Expert Android App Developers

https://www.youtube.com/watch?v=twmuBbC_oB8

Page 21: Android Jam - Services & Notifications - Udacity Lesson 6

SyncAdapter

● Designed to sync local data with web efficiently● OS Batches requests with other apps to save battery.● Try not to run when radio is idle● Auto retry requests ● onPerformSync

Page 22: Android Jam - Services & Notifications - Udacity Lesson 6

Notifications

Page 23: Android Jam - Services & Notifications - Udacity Lesson 6

Notifications

● So far, all solutions of retrieving data/sync go Device -> Server (Poll)

● Notifications are Server -> Device (Push)- ○ can include payload in json format or request update

■ NB: Requesting too many updates concurrently can cause server traffic

○ More efficient than polling

Page 24: Android Jam - Services & Notifications - Udacity Lesson 6

What went well

Page 25: Android Jam - Services & Notifications - Udacity Lesson 6

What went well

● Efficient data transfer very useful● SyncAdapters - many applications can make use of them● The 3 laws for application priority - great way to

remember● Understanding the state radio helps understand why

little data transfers are actually worse!

Page 26: Android Jam - Services & Notifications - Udacity Lesson 6

What didn’t go so well

Page 27: Android Jam - Services & Notifications - Udacity Lesson 6

What didn’t go so well

● Less detail in this class● There is a lot to learn / know to get efficient data

synchronised applications● Copy n Paste for the sync adapter● Didn’t delete the old weather data until this

lesson!● “comment out” refresh button … but woohoo

SyncAdapter

Page 28: Android Jam - Services & Notifications - Udacity Lesson 6

Q&A

Page 29: Android Jam - Services & Notifications - Udacity Lesson 6

Next - Android JamProject Retro

Page 30: Android Jam - Services & Notifications - Udacity Lesson 6

Next Lesson - Project

Learning Objectives:- Final Project

Page 31: Android Jam - Services & Notifications - Udacity Lesson 6

Final ProjectYour Project must:

Import and build on the latest version of Android Studio Be entirely self-contained on an Android device (No external devices/bluetooth peripherals). Include a problem description of the problem your app solves. Include mocks for all user-facing screens. Include at least one alternate mock for tablet / large screens. Implement all mockups, including your tablet layout. Have at least two distinct Views (ex. a list view and a detail view). Work properly with the app lifecycle (i.e. resume state on orientation change). Use permissions responsibly. Use Intents to move between activities inside your app or to an outside app. Create and use your own ContentProvider Use Loaders to move your data to your views. If the application pulls or sends data to/from a web service or API, it handles this network activity properly

(i.e on the correct thread, does not abuse network resources) Include only safe-for-work content in your app

Page 32: Android Jam - Services & Notifications - Udacity Lesson 6

Final Project ExtrasFor extra Udacious-ness, include at least two of the following (optional):

Receive Broadcast events and do something meaningful. Create and use a custom View. Implement a ShareActionProvider, sharing rich content such as a picture or link. Use Notifications.

Page 33: Android Jam - Services & Notifications - Udacity Lesson 6

Final Project Ideas● Food ordering app● Teleprompter app ● Local news app● App for your company, university or local club● Education app● Public transit schedule● Reddit Reading List● Github OSS project tracker

● YouTube API● Twitter API● Weather API● www.programmableweb.com/apis/directory

Page 34: Android Jam - Services & Notifications - Udacity Lesson 6

Final Project Paul

Page 35: Android Jam - Services & Notifications - Udacity Lesson 6

Final Project Zain

Page 36: Android Jam - Services & Notifications - Udacity Lesson 6

Final Project Checklist

Page 37: Android Jam - Services & Notifications - Udacity Lesson 6

See you next but one week..

- Time: Tuesday 31st March 7pm - Place: SpacePort- Things needed: You + Questions +

Feedback- Can contact us if issues:

@blundell_apps / @android_mcr

Page 38: Android Jam - Services & Notifications - Udacity Lesson 6

Go forth & discuss do