"Windows Phone 8 Development Internals" Reading notes -1-2-2-serial

Source: Internet
Author: User



Chapter II: Application Models and navigation (2)



Core issues in this chapter:


    1. The life cycle of an application
    2. The Navigation model of Microsoft page-based Silverlight application framework


We discussed the operating mechanism of WP, and now we go on to discuss the recovery strategy of WP:



In wp7.x, when we return to the application (without exiting) and then activate the application again, we can see from the previous article that it was restored in accordance with the epitaph state stored in the system, which is a slow process. Microsoft has introduced a new technology-recovery strategy (resume policy) for us in WP8, which allows applications to recover more quickly. The use of this strategy makes the application storage stack has an instance of the currently exiting application, and when we switch back, we call the instance of the object directly, thus appearing to respond faster.



When the program foreground is running, we press the window key to switch the program to the background. At this time, WP8 default fast recovery method is long press the back key, and we click on the Shelltile or the main program tile or program list icon to run the program, the program will jump to the history page stack of the latest page, jump parameter E. NavigationMode = = Navigationmode.reset, then automatically executes a new jump to the program default startup page or shelltile the specified page, and then cleans up the history page stack.



So, in order to run the program when you click on the main program tile or the program list icon to quickly revert to the last page, we need to cancel the new jump that was executed automatically, and keep the history page stack:



1. We need properties->wmappmanifest.xml


<DefaultTask Name = "_ default" NavigationPage = "MainPage.xaml" ActivationPolicy = "Resume" />
NavigationPage: Set the start page of the program

2. Modify the CheckForResetNavigation method of App.xaml.cs file as follows:

private bool _isResume = false;
// It is executed every time the page jump is completed. Here, it is judged whether it is the recovery mode
private void CheckForResetNavigation (object sender, NavigationEventArgs e)
{
    // Currently, when the program quickly restores to the last page browsed, the framework will automatically jump to the program default startup page or ShellTile specified page after this
    if (e.NavigationMode == NavigationMode.Reset)
    {
        // When quickly recovering, decide whether to cancel the automatic jump of the frame
        RootFrame.Navigating + = HandlerFotResetNavigating;
        _isResume = true;
    }
    else
    {
        if (_isResume && e.NavigationMode == NavigationMode.Refresh) // When you click the same tile for the second time to trigger a quick recovery, the frame will not automatically jump
        {
            RootFrame.Navigating-= HandlerFotResetNavigating;
            _isResume = false;
        }
    }
}
3. Implement the HandlerFotResetNavigating event:

// The frame automatically jumps in the fast recovery mode, here decides whether to cancel the jump
private void HandlerFotResetNavigating (object sender, NavigatingCancelEventArgs e)
{
    RootFrame.Navigating-= HandlerFotResetNavigating;
    if (e.Uri.OriginalString.Contains ("MainPage.xaml")) // Click the program main tile or program list icon to enter, it will jump to the default program startup page, then cancel the jump and restore to the history page stack Latest page
    {
        e.Cancel = true;
    }
    else // Click ShellTile to enter, it will jump to the page specified by ShellTile, then the jump is not canceled, and the history stack is cleared after the jump is completed
    {
        RootFrame.Navigated + = ClearBackStackAfterReset;
    }
    _isResume = false;
}
Second, the page navigation model

WP's navigation model is similar to traditional WEB navigation (jumping between pages, using URL to navigate, and can also be navigated from one application to another), usually the number of WP pages is maintained between 4-10, There can also be more pages and correspondingly more system resources will be consumed.


Figure 1-1: WP page navigation model

 

PS: This kind of navigation process can be considered as stacking and stacking. It is a good understanding of this process in combination with the forward and backward principles of the browser.

The WP page-> app, application-> page navigation model creates a seamless user experience.

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.