Ch07 生命週期(Life Cycle).

Slides:



Advertisements
Similar presentations
Charles Petzold Application Lifecycle and State Management.
Advertisements

Part 2: Manage app lifecycle and state (Windows Store apps using C#/VB and XAML) us/library/windows/apps/hh aspx
Understanding Mobile App Development Concepts and Working with APIs Lesson 6.
W8 – Unwrapping the not- so-obvious Kevin Dockx | 05/03/2013.
Essentials of Developing Windows Phone Apps Chinthaka Dissanayake Tech Lead Exilesoft.
Object Oriented Programming with Java (150704).   Applet  AWT (Abstract Window Toolkit)  Japplet  Swing Types of Applet.
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
OS Spring’03 Introduction Operating Systems Spring 2003.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Charles Petzold Navigation.
Windows Programming Using C# Windows Services, Serialization, and Isolated Storage.
Windows 8 applications with Azure backends Mihai Tataran General Manager, Avaelgo Microsoft Most Valuable Professional.
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
Introduction to Silverlight. Slide 2 What is Silverlight? It’s part of a Microsoft Web platform called Rich Internet Applications (RIA) There is a service.
By Lecturer / Aisha Dawood 1.  You can control the number of dispatcher processes in the instance. Unlike the number of shared servers, the number of.
Getting Started with Caliburn.Micro and Windows Phone 7 Gary Ewan Park Twitter: Blog:
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Rapid Development of High Performance Servers Khaled ElMeleegy Alan Cox Willy Zwaenepoel.
Operating Systems Lecture 7 OS Potpourri Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of Software.
Multiprogramming. Readings r Silberschatz, Galvin, Gagne, “Operating System Concepts”, 8 th edition: Chapter 3.1, 3.2.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
4300 Lines Added 1800 Lines Removed 1500 Lines Modified PER DAY DURING SUSE Lab.
Nachos Lecture 2 Xiaorui Sun. Phase 2 You have got one machine (machine package) You have to implements the incomplete OS (userprog package) Run programs.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
Lecture on Central Process Unit (CPU)
1 Process Description and Control Chapter 3. 2 Process A program in execution An instance of a program running on a computer The entity that can be assigned.
1 Lecture 19: Unix signals and Terminal management n what is a signal n signal handling u kernel u user n signal generation n signal example usage n terminal.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Windows 8: XAML or HTML? Karl Davies-Barrett CEE DPE Tech Lead, Microsoft 
Multithreading vs. Event Driven in Code Development of High Performance Servers.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Windows 8 App Development with XAML
Core ELN Training: Office Web Apps (OWA)
Becoming a Pro IN Mobile Applications Testing
Windows Calls Applications (windows.applicationmodel.calls)
Processes and threads.
TechEd /26/2018 3:42 AM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Chapter 2: System Structures
Day 08 Processes.
Activities and Intents
Build Windows 10 UWP MVVM Apps with Prism
Introduction to Operating System (OS)
Intro to Processes CSSE 332 Operating Systems
CSI 400/500 Operating Systems Spring 2009
Introduction to Silverlight
IOS App Development.
Affordable iPhone Mobile Apps Development Services Company
Android Programming Lecture 9
Microsoft Build /9/2018 8:05 PM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Process management Information maintained by OS for process management
11/19/ | App Model & Storage © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
Metro style apps using XAML: Make your app shine
Tooling and Diagnostics
Windows Runtime App Lifecycle
Process Description and Control
HNDIT2417 Mobile Application Development
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Interrupt handling Explain how interrupts are used to obtain processor time and how processing of interrupted jobs may later be resumed, (typical.
Activities and Intents
Chapter 3: Processes.
4/9/ | Contracts © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Michael Palermo Jeremy Foster
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
A very brief introduction
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
04 | State Management Bill Burrows | UW Faculty Member & VB MVP
03 | Branding & Monetization
Presentation transcript:

Ch07 生命週期(Life Cycle)

為何要了解及管理App的生命週期 手機的資源(Power,記憶體,)是有限的 手機作業系統一般在同一時間只能一個App 在前景執行 (foreground App) 其他的App則被 suspended 或 terminated 手機作業系統有不同的機制讓一個App轉換到前景執行 手機作業系統有不同的機制讓一個App在背景執行

Window Phone App的生命週期 App還未啟動(launch)是在NotRunning的狀 態。 當使用者執行App後,它進入Running的狀 態。 當App進入啟動另一App,或是在Low Power的狀態它進入Supended 狀態。(App 不可見,但被存在記憶體中) 當Windows Phone轉換回(Resuming)此App, 此App回到Running的狀態。(此時的狀態 為App Suspended之前的狀態,資料都還 在) 當使用者關閉一個App或一個App在 suspended狀態,且此時作業系統因記憶 體不足自動將此App終止,會進入Not Running的狀態。 NotRunning state (https://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx) it has never been launched it was running but then crashed it was suspended but then couldn't be kept in memory and was terminated by the system. Activated (restore previously saved data ) (OnActivated event) Windows displays a splash screen for the app to register event handlers and set up any custom UI it needs for loading the initial page. If an app needs to request data from the network or needs to retrieve large amounts of data from disk, these activities should be completed outside of activation.  Suspended (save its state and release its exclusive resources and file handles immediately when handling the suspending event,) the user switches away from it when the device enters a low power state. When the user moves an app to the background, Windows waits a few seconds to see whether the user immediately switches back to the app. If the user does not switch back within this time window, Windows suspends the app. Windows attempts to keep as many suspended apps in memory as possible. However, if there aren't enough resources to keep your app in memory, Windows can terminate your app. Individual apps don't receive notification that they are being terminated, so the only opportunity you have to save your app's data is during suspension. Resuming event HTML apps usually don't need to handle resuming  If a suspended app is activated to participate in an app contract or extension, it receives the Resuming event first, then the Activated event. When an app is suspended, it does not receive network events that it registered to receive. These events are not queued, they are simply missed. Therefore, your app should test the network status when it is resumed. App close Generally, users don't need to close apps, they can let Windows manage them.  After an app has been closed by the user, it's suspended and terminated, and then enters the NotRunning state.

App Class 大部分生命週期相關的方法都是在App Class (App.xaml.cs) App的進入點 管理App的生命週期 OnLaunched():當App在初始啟動時執行。 OnSuspending():進入到Suspended狀態前執行,通常在此 將App的狀態存起來。 管理可在整個App被使用的資源,如 <Application.Resources>、Frame物件。

設定App啟動時第一個執行的Page 新增一WelcomePage.xaml 基本頁面會自動增加幾個Class,這些Class提供Navigation 和生命週期管理等功能

練習CH07-01 請完成上一張投影片的程式碼

在suspended前儲存Frame的瀏覽資料並在下次啟動時回復(1) 1. 在App.xaml.cs的OnLaunched方法註冊需要suspending 管理的 Frame You set the CacheSize property to specify how many pages can be retained in a cache. When a page is cached, an instance of the page is reused for each navigation request rather than re-creating the page for each request. XAML Metro app: Complex objects as parameter when navigating between pages causes crash https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash The types stored by individual pages must be able to be serialized by the DataContractSerializer in C# and VB. To do this any custom type must be registered before it can be saved or restored. SuspensionManager provides the KnownTypes collection which passes the types in the collection to the DataContractSerializer. As the SuspensionManager is called to restore state in the OnLaunched override of the code behind for App.xaml, a good place to register types is in the app constructor. The parameters passed in using navigation must be able to be serialized by the platform. When we are saving and restoring the navigation stack, we call Frame.GetNavigationState() and Frame.SetNavigationState(). Both of these calls make use of an internal serialization format and all types passed as the parameter in Frame.Navigate() must be able to be serialized by the platform. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

在suspended前儲存Frame的瀏覽資料並在下次啟動時回復(2) 2. 在App.xaml.cs的OnSuspending方法儲存Frame的狀態 You set the CacheSize property to specify how many pages can be retained in a cache. When a page is cached, an instance of the page is reused for each navigation request rather than re-creating the page for each request. XAML Metro app: Complex objects as parameter when navigating between pages causes crash https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash The types stored by individual pages must be able to be serialized by the DataContractSerializer in C# and VB. To do this any custom type must be registered before it can be saved or restored. SuspensionManager provides the KnownTypes collection which passes the types in the collection to the DataContractSerializer. As the SuspensionManager is called to restore state in the OnLaunched override of the code behind for App.xaml, a good place to register types is in the app constructor. The parameters passed in using navigation must be able to be serialized by the platform. When we are saving and restoring the navigation stack, we call Frame.GetNavigationState() and Frame.SetNavigationState(). Both of these calls make use of an internal serialization format and all types passed as the parameter in Frame.Navigate() must be able to be serialized by the platform. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

在suspended前儲存Frame的瀏覽資料並在下次啟動時回復(3) 3. 在App.xaml.cs的OnLaunched方法回復Frame的狀態 You set the CacheSize property to specify how many pages can be retained in a cache. When a page is cached, an instance of the page is reused for each navigation request rather than re-creating the page for each request. XAML Metro app: Complex objects as parameter when navigating between pages causes crash https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash The types stored by individual pages must be able to be serialized by the DataContractSerializer in C# and VB. To do this any custom type must be registered before it can be saved or restored. SuspensionManager provides the KnownTypes collection which passes the types in the collection to the DataContractSerializer. As the SuspensionManager is called to restore state in the OnLaunched override of the code behind for App.xaml, a good place to register types is in the app constructor. The parameters passed in using navigation must be able to be serialized by the platform. When we are saving and restoring the navigation stack, we call Frame.GetNavigationState() and Frame.SetNavigationState(). Both of these calls make use of an internal serialization format and all types passed as the parameter in Frame.Navigate() must be able to be serialized by the platform. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

在suspended前儲存Frame的瀏覽資料並在下次啟動時回復(4) SuspensionManager只能儲存 基本型態的資料如int, string,所以在 傳遞多個參數時要將其以字串傳遞 使用”週期事件”下拉選單轉換App狀態 Frame.Navigate(typeof(ShowName),user); Frame.Navigate(typeof(ShowName), this.tbUserName.Text + "," + this.pbPassword.Password + "," + "Assets/ko.jpg"); User user = (User)e.Parameter; string[] user = e.Parameter.ToString().Split(','); You set the CacheSize property to specify how many pages can be retained in a cache. When a page is cached, an instance of the page is reused for each navigation request rather than re-creating the page for each request. XAML Metro app: Complex objects as parameter when navigating between pages causes crash https://connect.microsoft.com/VisualStudio/feedback/details/753331/xaml-metro-app-complex-objects-as-parameter-when-navigating-between-pages-causes-crash The types stored by individual pages must be able to be serialized by the DataContractSerializer in C# and VB. To do this any custom type must be registered before it can be saved or restored. SuspensionManager provides the KnownTypes collection which passes the types in the collection to the DataContractSerializer. As the SuspensionManager is called to restore state in the OnLaunched override of the code behind for App.xaml, a good place to register types is in the app constructor. The parameters passed in using navigation must be able to be serialized by the platform. When we are saving and restoring the navigation stack, we call Frame.GetNavigationState() and Frame.SetNavigationState(). Both of these calls make use of an internal serialization format and all types passed as the parameter in Frame.Navigate() must be able to be serialized by the platform. https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh771188.aspx

練習CH07-02 請完成上一張投影片的程式碼

在suspended前儲存資料並在下次啟動時回復(1) 註冊事件

在suspended前儲存資料並在下次啟動時回復(2) 在OnNavigatedTo方法增加this.navigationHelper.OnNavigatedTo(e); 在OnNavigatedFrom方法增加this.navigationHelper.OnNavigatedFrom(e);

在suspended前儲存資料並在下次啟動時回復(3) 增加NavigationHelper_SaveState方法 SaveStateEventArgs有一個property PageState,PageState是一個dictionary用以存 資料

在suspended前儲存資料並在下次啟動時回復(4) 增加NavigationHelper_LoadState方法

練習CH07-03 請完成上一張投影片的程式碼