il ciclo di vita fast application switching e fast resume
TRANSCRIPT
![Page 1: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/1.jpg)
IL CICLO DI VITA:FAST APPLICATION SWITCHING E FAST RESUMEDan ArdeleanNokia Developer [email protected] Twitter: @danardelean
NOKIA WEBINAR
![Page 2: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/2.jpg)
Stack di navigazioneLaunching & ClosingDormant & TombstonedDizionari di statoFast Application ResumeObscured & UnobscuredAsync & await
AGENDA
![Page 3: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/3.jpg)
• Modello di navigazione Page-Based
• Per implementare questo modello di navigazione ogni applicazione ha uno «Back Stack»• Navigazione verso una nuova pagina la vecchia viene inserita in Back Stack• Quando viene premuto il tasto Back o chiamato il metodo GoBack
l’applicazione ritorna alla prima pagina dentro Back Stack• Se Back Stack è vuoto quando si naviga indietro l’applicazione viene chiusa
LE BASI
![Page 4: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/4.jpg)
• Possiamo manualmente rimuovere elementi dallo stack
• Non possiamo manualmente aggiungere elementi• Le pagine possono essere notificate se vengono rimosse dallo
stack
STACK DI NAVIGAZIONE
private void PurgeBackStackButton_Click(object sender, RoutedEventArgs e){ while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry();}
protected override void OnRemovedFromJournal(JournalEntryRemovedEventArgs e){ base.OnRemovedFromJournal(e);}
![Page 5: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/5.jpg)
Not running
Running
Launching
LANCIO APPLICAZIONE
![Page 6: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/6.jpg)
Not running
Running
LaunchingClosing
Deactivating
Dormant
ExitApplication_Closing
DeactivateApplication_Deactivated
Dormant
CHIUSURA & DISATTIVAZIONE
![Page 7: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/7.jpg)
Istanza in memoria
Stato applicazione, data e oggetti non vengono modificati
Deve essere pronta per essere chiusa
DORMANTNot running
Running
LaunchingClosing
DeactivatingActivating
Dormant
![Page 8: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/8.jpg)
Att
iva
Dorm
an
tTo
mbst
oned
![Page 9: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/9.jpg)
Tombstoned
Not running
Running
LaunchingClosing
DeactivatingActivating
Dormant
Da Dormant a Tombstone «memory based»
Salva i dizionari di stato e lo stack di navigazione
Bisogna ricaricare i dati
TOMBSTONED
![Page 10: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/10.jpg)
Tombstoned
Not running
Running
LaunchingClosing
DeactivatingActivating
Dormant
TOMBSTONED O DORMANT?
private void Application_Activated(object sender, ActivatedEventArgs e){ if (e.IsApplicationInstancePreserved) { // Dormant } else { // Tombstoned }}
![Page 11: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/11.jpg)
Riattiva l’istanza dormant se l’utente lancia una nuova istanza
Necessario per le applicazioni che fanno tracking della posizione e non solo
FAST APPLICATION RESUME
Tombstoned
Not running
Running
LaunchingClosing
DeactivatingActivating
Dormant
![Page 12: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/12.jpg)
Dormant/TombstonedDEMO
![Page 13: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/13.jpg)
TERMINAZIONE NORMALEUtente MainPagePhone OS Applicazion
eLancio l’applicazione
Costruttore applicazione App()
Application_Launching
Costruttore MainPage
MainPage OnNavigatedTo
Utilizzo applicazione
Back
MainPage OnNavigatingFrom
MainPage OnNavigatedFrom
Application_Closing
![Page 14: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/14.jpg)
DORMANTUtente MainPagePhone OS Applicazion
e
Utilizzo applicazione
Start
MainPage OnNavigatingFrom
MainPage OnNavigatedFrom
Application_DeactivatedBack
Application_Activated
MainPage OnNavigatedTo
Utilizzo applicazione
IsApplicationInstancePreserved==true
![Page 15: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/15.jpg)
Application_Activated
TOMBSTONEDUtente MainPagePhone OS Applicazion
eUtilizzo applicazione
Start
MainPage OnNavigatingFrom
MainPage OnNavigatedFrom
Application_Deactivated
Back
IsApplicationInstancePreserved==false
Processo terminato
Costruttore applicazione App()
Costruttore MainPageMainPage OnNavigatedTo
Utilizzo applicazione
![Page 16: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/16.jpg)
Application_Activated
TOMBSTONEDUtente MainPagePhone OS Applicazion
eUtilizzo applicazioneIn-App
Navigation SecondPage Costruttore
MainPage OnNavigatedFrom
Application_Deactivated
Start
Processo terminato
Costruttore App()
Costruttore MainPage
MainPage OnNavigatedTo
SecondPage
SecondPage OnNavigatedTo
Back
SecondPage Costruttore
SecondPage OnNavigatedToBack
SecondPage OnNavigatedFrom
![Page 17: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/17.jpg)
• 3 Dizionari
• Pagina:PhoneApplicationPage.State
• Istanza appPhoneApplicationService.Current.State
• ApplicazioneSystem.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings
STATO APPLICAZIONE
![Page 18: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/18.jpg)
Sospensione Timers e Thread
MANAGEMENT DELLE RISORSEUtente MainPagePhone OS Applicazion
eUtilizzo applicazione
Start
MainPage OnNavigatingFrom
MainPage OnNavigatedFrom
Application_Deactivated
Rilascio risorse
MediaPlayer.PauseMediaElement.PauseVibrateController.StopPhotocamera.Dispose
Set to Dormant state
Rilascio risorseXNA Audio in pausaNessuna notifica dagli sensoriInterrompe le chiamate di reteScollega socketScollega mediaDispose Photocamera
![Page 19: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/19.jpg)
Ripristino Timers e Thread
MANAGEMENT DELLE RISORSEUtente MainPagePhone OS Applicazion
e
Back
MainPage OnNavigatedTo
Application_Activated
Ripristino risorse
MediaPlayer.PlaySocket.ConnectAsyncnew PhotoCamera
Ripristino risorse XNA Audio in play
Ripristina notifiche dagli sensoriRipristina le chiamate di rete
Socket rimangano scollegatiMediaElement non connessoPhotocamera disposed
![Page 20: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/20.jpg)
• Riattiva l’istanza Dormant, se esiste, quando l’utente lancia nuovamente l’applicazione
• Per abilitare la funzionalità bisogna modificare Properties\WMAppManifest.xml
FAST APPLICATION RESUME
<Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml" ActivationPolicy="Resume"></Tasks>
![Page 21: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/21.jpg)
Fast Application ResumeDEMO
![Page 22: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/22.jpg)
• Quando l’interfaccia utente viene oscurata: notifiche toast, lockscreen, chiamata in arrivo
• L’applicazione continua girare in background
• Per far girare l’applicazione dietro Lockscreen
• Per disabilitare il Lockscreen
OBSCURED & UNOBSCURED
PhoneApplicationService.Current.ApplicationIdleDetectionMode = IdleDetectionMode.Disabled;
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
![Page 23: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/23.jpg)
• Cosa succede quando usiamo async e await per Application_Closing e Application_Deactivate?
• Meccanismo per applicazioni Windows Store
ASYNC E AWAIT
var deferral = e.SuspendingOperation.GetDeferral();//TODO: Save application state and stop any background activity. await ExecuteAsync(); deferral.Complete();
![Page 24: Il ciclo di vita fast application switching e fast resume](https://reader035.vdocuments.us/reader035/viewer/2022070314/554d1c15b4c905ab268b4572/html5/thumbnails/24.jpg)
04/11/2023© 2013 Nokia. All rights reserved.© 2013 Microsoft. All rights reserved.
Grazie!
Blog: sviluppomobile.blogspot.comEmail: [email protected]: @danardelean