Windows Phone application tombstone execution model Summary

Source: Internet
Author: User
Tags home screen
1. WP third-party applications Program Restrictions


WP allows only one third-party application to run at a time in the foreground. This means that the user can only start one third-party application when operating the mobile phone, making people think that WP is a single-task operating system.



However, unlike the generally-understood single-task operating system, WP provides a mechanism, which is Tombstone (tombstone ), it allows users to retain their previous operation status when switching between different third-party applications (this is what the multitasking operating system is best at), improving the user experience.



 


Ii. Tombstone


Tombstone is a tombstone. It can also be intuitively understood as sleep, suspended, paused, or frozen. In WP, it indicates a flag of program termination, however, it cannot be understood that the process is completely terminated and the application is exited.



Tombstone provides Windows Phone with the ability to perform multiple tasks in a single task.. How can we implement the multi-task function with the single-task capability?



The answer is the tombstone execution model provided by WP.



 


Iii. WP Lifecycle


Familiarize yourself with the life cycle of WP before talking about the tombstone execution model.



Tombstone is an important state in the WP life cycle. It is an event-based execution model. The following figure compares the similarities and differences between WP7 and wp7.5 lifecycle management:



1. WP7 application Lifecycle Process






2. wp7.5 application Lifecycle Process



In the following figure, the circle indicates the application state, and the rectangle shows the application level or page level event where the application should manage its State.






Note: The images are from the reference blog.



 


4. Tombstone execution model


1. Execution Process



Tombstone is an event-based execution model. In WP7, there are four basic processing events: launching, closing, activated, and deactivated. Each application activation will trigger at least one of the events. Whether the program is Tombstone depends entirely on the events that the program currently enters. These events are managed and described by the project's entry file app. XAML. CS.



Create a WP project and open app. XAML. CS under the project. You can see the processing functions of the following four basic events:


 
 // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
        }

        // Code to execute when the application is activated (brought to foreground)
        // This code will not execute when the application is first launched
        private void Application_Activated(object sender, ActivatedEventArgs e)
        {
        }

        // Code to execute when the application is deactivated (sent to background)
        // This code will not execute when the application is closing
        private void Application_Deactivated(object sender, DeactivatedEventArgs e)
        {
        }

        // Code to execute when the application is closing (eg, user hit Back)
        // This code will not execute when the application is deactivated
        private void Application_Closing(object sender, ClosingEventArgs e)
        {
        }

 



Where,Application_deactivated is the action performed when a tombstone event occurs, and application_activated is the event action when Tombstone is restored..



We can handle these four events by programming tombstone (deactivated event) and Relief (activated event), such as saving temporary data when Tombstone is generated, when tombstone is removed, temporary data is taken out. For users, one-store-one operation ensures consistent user experience.



 



2. Handling events



(1) Launching events



A launching event is an event that must be executed by a third-party application during its first running. It is mainly responsible for application initialization. This event corresponds to the closing event. A normal application executes the launching event, and the closing event must be executed in the end.



The launching event must be started for the first time and will not be executed by applications in the tombstone release state.



Features of this event:It is called when the program is started for the first time and not when the program is re-activated..



 



(2) activated event



Activated events are at the core of Tombstone. To determine whether an application enters tombstone, you only need to observe whether the activated event is being executed. This event is suitable for reading some temporary data.



Every activated application is intuitively visible to users in the mobile phone front-end application. At this time, you can think that this front-end application has been activated.



Features of this event:Called when the program is re-activated, not when the program is started.



 



(3) Deactivated event (the event where the application enters tombstone)



The deactivated (deactivated) event and activated event form a complete tombstone. That is to say, when the application executes the deactivated event, the application will be in Tombstone (sleep state), and only the activated event can be awakened again.



However, you must note that deactivated events are isolated and do not correspond to any one of them. That is to say, if the program is in deactivated, You can trigger any of the launching, closing, and activated events.



The following are several common scenarios where WP executes deactivated events:



A. You can click the start button to return to the home screen or start another application;



B. The mobile phone screen is locked;



C. Call in or receive a new text message;



D. Push Service or other message reminders;



E. A warning is triggered when the battery power is low.



Features of this event:Called when the program is disabled or not called when the program is closed..



 



(4) closing events



The closing (close) event corresponds to the launching event, although an application may not be able to execute this event (for example, a dead machine, a cell phone without power, or other uncaptured exceptions ).



Features of this event:This event is called when the program is closed. If the program is not activated, it is not called..



 



You can refer to the followingCodeTo track the output window of vs at startup, When you click the start button of the simulator, and when you click the back button to deepen your understanding of these four events:


 
/// <summary>
        /// will be called when the program is first started, not called when the program is reactivated
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void Application_Launching (object sender, LaunchingEventArgs e)
        {
            Debug.WriteLine ("{0} entered Launching event", DateTime.Now.ToLongTimeString ());
        }

        /// <summary>
        /// Called when the program is reactivated Not called when the program starts
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void Application_Activated (object sender, ActivatedEventArgs e)
        {
            Debug.WriteLine ("{0} entered Activated event", DateTime.Now.ToLongTimeString ());
            if (PhoneApplicationService.Current.State.ContainsKey (phoneApplicationServicedata))
            {
                string content = PhoneApplicationService.Current.State [phoneApplicationServicedata] as string;
                Debug.WriteLine ("{0}", content);
            }
        }

        /// <summary>
        /// Called when the program is deactivated Not called when the program is closed
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void Application_Deactivated (object sender, DeactivatedEventArgs e)
        {
            Debug.WriteLine ("{0} entered Deactivated event", DateTime.Now.ToLongTimeString ());
            string content = "Hello Windows Phone!";
            if (content! = null)
            {
                PhoneApplicationService.Current.State [phoneApplicationServicedata] = "Temporary data:" + content;

            }
        }

        /// <summary>
        /// Called when the program is closed Do not call when the program is deactivated
        /// </ summary>
        /// <param name = "sender"> </ param>
        /// <param name = "e"> </ param>
        private void Application_Closing (object sender, ClosingEventArgs e)
        {

            Debug.WriteLine ("{0} entering Closing event", DateTime.Now.ToLongTimeString ());
        }


 



 



Refer:



Http://msdn.microsoft.com/zh-cn/library/ff817008 (V = vs.92). aspx



Http://www.cnblogs.com/linzheng/archive/2011/02/14/1954764.html


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.