Windows Phone development experience (1)-Basic Concepts

Source: Internet
Author: User


(1) Windows Phone execution model:

Purpose:Always provide end users with a quick response experience

Features:Windows Phone allows only one application to run on the foreground at any given time. When the application is no longer running on the foreground, the operating system changes the application to sleep.

Processing principles:If the device memory that can be used for foreground applications is insufficient to provide excellent user experience, the operating system will terminate the applications that are sleeping (first terminate the applications that are oldest)

 

(2) Basic concepts:

Application Status:Data used by multiple pages in the Application

Page Status:Current visual status of a single application page

Application events: [lifecycle functions in Android applications ]. Here there are four, respectively:Launching, deactivated, activatedAndClosing. The processing of these events is included in the application object [this object is
Part of the Visual Studio Project template of the Windows Phone application. You will write code in these event handlers to manage the application status ].

Note that: All application events allow the application to complete tasks in the event processing program within 10 seconds. If an application exceeds this limit, it is terminated immediately. Therefore, you should avoid executing resource-intensive tasks, such as reading data from and writing data to the independent storage within the processing program of application events. When the application is running, these tasks should be executed through background threads as much as possible. Saving application data as the application data changes throughout the life of the application reduces the State management workload that needs to be executed during application events.

Page events:All Windows Phone pages are inherited fromPhoneapplicationpageIt exposes two methods: onnavigatedto (navigationeventargs) and onnavigatedfrom (navigationeventargs). The application will override these two methods to manage the page status. Specifically, these two methods are in the page object, while phoneapplicationpage inherits the page class. Through the provided API, we can know that these two methods are located in the page class.

Logical deletion:During this process, the application is terminated, but data about the application status and various pages in the application is retained. The stored data includes the currently displayed application page and the back stack of the previously accessed page in the application. If you navigate back to the logically deleted application, the application is re-created and the current page and page history are automatically restored. Here we can use the above two page event functions. I will demonstrate a demo for you later.

 

(3) Windows Phone application Lifecycle

It is always the best way to illustrate the truth with graphs:

 

Let's give another demo.

Select app. XAML under the project directory to see the following code:

<Application. applicationlifetimeobjects> <! -- Objects required to process the Lifetime Events of an Application --> <shell: phoneapplicationservice launching = "application_launching" Closing = "application_closing" activated = "application_activated" Deactivated = "application_deactivated"/> </application. applicationlifetimeobjects>

 

Then open the "Properties dialog box"

Here there are four events in four lifecycles. Alternatively, you can directly open the app. XAML. CS file and view the four event functions that have been written in the four lifecycles.

 

Source code:

 

// Code executed when the application is started (for example, starting from the "Start" menu) // This Code does not execute privatevoid application_launching (Object sender, launchingeventargse) when the application is re-activated) {debug. writeline ("----------------------- launching ---------------------------");} // activate the application (on the frontend) code executed when the application is started for the first time // This Code does not execute privatevoid application_activated (Object sender, activatedeventargse) {debug. writeline ("--------------------- activated ---------------------------");} // code executed when the application is disabled (sent to the background) // This Code does not run private voidapplication_deactivated (Object sender, deactivatedeventargs e) {debug. writeline ("----------------------- deactivated ---------------------------");} // close the application (for example, the user clicks "back ") code to be executed // This Code does not execute privatevoid application_closing (Object sender, closingeventargse) {debug. writeline ("--------------------- closing -----------------------------");}

1. When our application starts, we can see the following output information:

2. Click "searchtask" to start a new task. At this time, our application will be suspended. This is what we call the tombstone mechanism. Its status is deactivated.

The output information is as follows:

 

3. When we click return, our application will become activated again.

The output information is as follows:

4. When we click "return" again, this means that we quit the application and the state of our application is closing. The output information is as follows:

 

I believe that some of the above introductions can be used. You have some knowledge of these concepts.

 

(4) Summary of model events and application operations

Then, let's give the official Microsoft suggestions:

Events or methods

Application operations

Launching event

Execute a very small amount of code. Do not perform resource-intensive operations, such as accessing independent storage.

Onnavigatedfrom Method

If you do not navigate backward, save the UI status to the State dictionary.

Deactivated event

When an application is logically deleted, the application state is saved to state. At the same time, the Persistence State is saved to the independent storage when the application is terminated. When the application enters the sleep state, do not destroy the State of the application in the memory.

Activated event

Check isapplicationinstancepreserved. If this parameter is set to true, no operation is performed. If the value is false, the application state is restored using the data in the state.

Onnavigatedto Method

Check whether the page is a new instance. If not, the status is automatically maintained. Otherwise, use this data to restore the UI if there is data in the state.

Closing events

Store continuous application data to independent storage.

 

Note: most of the basic concepts described above are also taken from Microsoft official documents.

If you need to reprint reference please indicate the source: http://blog.csdn.net/jiahui524

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.