22
Multitasking, background agents and local notifications Mobile Software Engineer @ Gaia Microsoft MVP – Device Application Development Twitter: @qmatteoq Facebook: http://www.facebook.com/matteo.pagani Blog: http://qmatteoq.tostring.it E-mail: [email protected] Matteo Pagani

Multitasking, background agents and local notifications

Embed Size (px)

Citation preview

Page 1: Multitasking, background agents and local notifications

Multitasking, background agents and local

notifications

Mobile Software Engineer @ GaiaMicrosoft MVP – Device Application Development

Twitter: @qmatteoqFacebook: http://www.facebook.com/matteo.paganiBlog: http://qmatteoq.tostring.itE-mail: [email protected]

Matteo Pagani

Page 2: Multitasking, background agents and local notifications

Agenda

Fast App Switching Multiple tiles Background agents Reminders

Page 3: Multitasking, background agents and local notifications

Application lifecycle di Windows Phone

Running

Deactivated

Tombstoned

Activated

Save state

Restore state

Page 4: Multitasking, background agents and local notifications

Application lifecycle di Mango

Running

Deactivated

Dormant

Activated

Tombstoned

Save state

Restore state

Page 5: Multitasking, background agents and local notifications

Applicatione lifecycle di Mango

Dormant Il processo non viene terminato, ma rimane in background Vengono terminati tutti i thread e i timer in esecuzione Vengono scollegate tutte le risorse in uso (camera, rete, ecc.)

Tombstoned In caso ci sia bisogno di risorse, le applicazioni dormant più

vecchie vengono comunque mandate in tombstone.

Activated La proprietà IsApplicationInstancePreserved ci dice se

l’applicazione è andata in tombstoned oppure no. In caso sia a false, occorre recuperare lo stato dal tombstone.

Deactivated Occorre comunque salvare lo stato della nostra applicazione

Page 6: Multitasking, background agents and local notifications

DeactivatedWindows Phone si occupa di

disconnettere e fermare tutto ciò che possa consumare risorse in eccesso.

XNA Audio Paused

Sensors Notifications suppressed

Networking Cancelled

Sockets Disconnected

MediaElement Disconnected

Camera Disposed

Page 7: Multitasking, background agents and local notifications

ActivatedNon tutte le risorse vengono riattivate in automatico: alcune devono essere

manualmente riattivate dall’applicazione.

XNA Audio Resumed

Sensors Notifications resumed

Networking Completed with Cancellation

Sockets -

MediaElement -

Camera -

Page 8: Multitasking, background agents and local notifications

MULTIPLE TILESUn’invasione di tile sullo schermo

Page 9: Multitasking, background agents and local notifications

Multiple tiles

Un’app può creare da codice più tile in home

Ogni tile è identificata univocamente da un deep link

Le tile possono essere aggiornate sia localmente che da remoto

Page 10: Multitasking, background agents and local notifications

Multiple tiles<?xmlversion="1.0"encoding="utf-8"?> <wp:Notification xmlns:wp="WPNotification"> <wp:Tile Id="/DetailView.xaml?ID=5"> <wp:BackgroundImage></wp:BackgroundImage> <wp:Count></wp:Count> <wp:Title></wp:Title> <wp:BackTitle></wp:BackTitle> <wp:BackContent></wp:BackContent> <wp:BackBackgroundImage></wp:BackBackgroundImage> </wp:Tile> </wp:Notification>

Page 11: Multitasking, background agents and local notifications

LET’S CODE!

Page 12: Multitasking, background agents and local notifications

BACKGROUND AGENTSEseguiamo operazioni in background

Page 13: Multitasking, background agents and local notifications

Background agents Un progetto Visual Studio separato da quello

dell’applicazione vera e propria.

Vengono istanziati dall’applicazione foreground ma eseguiti in background quando questa non è in esecuzione.

Possono coesistere massimo 18 agents contemporaneamente.

L’utente può abilitarli o disabilitarli da un apposito pannello di controllo.

Vengono disattivati dopo 14 giorni che l’applicazione collegata non viene utilizzata.

Page 14: Multitasking, background agents and local notifications

Cosa possono fare?

Consentito

Tiles Toast Servizi di localizzazione Connettività Accesso all’Isolated Storage Sockets La maggior parte delle API

Non consentito

Interagire con la UI Librerie XNA Microfono e fotocamera Sensori Riprodurre audio senza

l’ausilio delle apposite API per il background audio

Page 15: Multitasking, background agents and local notifications

Periodic agents Vengono eseguiti ogni 30 minuti

Possono eseguire operazioni per un tempo massimo di 15 secondi

Se il device è in uso, vengono eseguiti uno alla volta

Se il device è in stand by, vengono eseguiti in parallelo

Nascono per task di sincronizzazione veloce, geo localizzazione, notifiche, ecc.

Page 16: Multitasking, background agents and local notifications

Resource Intensive agents

Vengono eseguiti solo nel momento in cui il device è in ricarica (collegato al pc o ad una presa di corrente)

Il device deve essere collegato ad una rete Wi-Fi

Possono eseguire operazioni per un tempo massimo di 10 minuti

Nascono per task di sincronizzazioni di grandi quantità di dati

Page 17: Multitasking, background agents and local notifications

LET’S CODE!

Page 18: Multitasking, background agents and local notifications

ALARMS & REMINDERSPer gli utenti smemorati

Page 19: Multitasking, background agents and local notifications

Alarms

Promemoria non legato ad un contesto applicativo specifico

Possibilità di impostare un suono personalizzato

Pulsanti snooze e dismiss

Page 20: Multitasking, background agents and local notifications

Reminders

Legati ad un contesto applicativo

Supporto ai deep link Pulsanti snooze e

dismiss con snooze personalizzabile

Page 21: Multitasking, background agents and local notifications

LET’S CODE!

Page 22: Multitasking, background agents and local notifications

Grazie!

Mobile Software Engineer @ GaiaMicrosoft MVP – Device Application Development

Twitter: @qmatteoqFacebook: http://www.facebook.com/matteo.paganiBlog: http://qmatteoq.tostring.itE-mail: [email protected]

Matteo Pagani