Windows Phone development (3): chess piece not moved, first view global turn: http://blog.csdn.net/tcjiaan/article/details/7253259

Source: Internet
Author: User

Before proceeding with WP development, like other development technologies, we need to have a brief understanding of the lifecycle of a WP application sequence. We do not have to understand it in depth, but at least we need to know what we should do and what operations are not recommended in every stage of the application life cycle, so that we can develop higher performance, better applications lay a solid foundation.

 

Is the official WP application execution model diagram.

 

 

Pay attention to the following four events:

1. Launching events.

To put it bluntly, it is the event triggered when the application is just started. Due to the special nature of this event, do not perform a lot of operations in the event handler, such as time-consuming jobs, why? Think about it. If a certain operation consumes a lot of time, you will surely find that the program starts very slowly. As a result, the user will be very upset, the user experience is compromised.

2. Activated event.

The application is triggered when it is activated. For example, if there is a button in my program, the user clicks it and opens the "window" for sending a text message. After the user sends the text message, the page for sending the text message is closed, at this time, our application is changed from the background program to the foreground program, and the activated event is triggered. Note that this event is not triggered when the program is started for the first time.

3. deactivated event.

Compared with the activated event, for example, when I click the button in the program, the page that sends the text message will start. At this time, the current application is blocked by the previous text message page. That is to say, when the current application is sent to the background, the deactivated event is triggered at this time. However, if the application is closed, this event is not triggered.

4. Closing events.

You can literally guess when the event happened. Yes, it occurs when the application is closed, but it is not sent to the background in the application's navigation. For example, after opening the text message page, even though the program is sent to the background, however, it is not triggered because it is still running and does not exit. However, if I start the program from the start or desktop tile and then return to the desktop through the return key, this event is triggered because the program exits.

 

 

To verify how these events occur, we write the debugging output code for these events in the app. XAML. CS file.

[CSHARP]View plaincopyprint?

  1. // Code executed when the application is started (for example, starting from the "Start" menu)
  2. // This code is not executed when the application is re-activated;
  3. Private void application_launching (Object sender, launchingeventargs E)
  4. {
  5. System. Diagnostics. Debug. writeline (datetime. Now. tow.timestring () + "-application started for the first time. ");
  6. }
  7. // Code executed when the application is activated (placed on the frontend)
  8. // This code is not executed when the application is started for the first time
  9. Private void application_activated (Object sender, activatedeventargs E)
  10. {
  11. System. Diagnostics. Debug. writeline (datetime. Now. tow.timestring () + "-the application is activated. ");
  12. }
  13. // Stop the code executed when the application (sent to the background)
  14. // This code is not executed when the application is closed
  15. Private void application_deactivated (Object sender, deactivatedeventargs E)
  16. {
  17. System. Diagnostics. Debug. writeline (datetime. Now. tow.timestring () + "-application sleep. ");
  18. }
  19. // Code executed when the application is closed (for example, when the user clicks back)
  20. // This code is not executed when the application is disabled
  21. Private void application_closing (Object sender, closingeventargs E)
  22. {
  23. System. Diagnostics. Debug. writeline (datetime. Now. tow.timestring () + "-close the application. ");
  24. }

Then, we run the program. When the page appears, click "return" on the simulator to close the program.

At this time, let's take a look at the "output" window.

Through this experiment, we found that the activated and deactivated events were not triggered. Why? Think for yourself.

 

Next, we put a button in the page and click the button to open the text message sending page.

[HTML]View plaincopyprint?

  1. <! -- Contentpanel-place other content here -->
  2. <Grid X: Name = "contentpanel" grid. Row = "1" margin = "12,0, 12,0">
  3. <Button verticalalignment = "TOP"
  4. Horizontalalignment = "center"
  5. Content = "Click me"
  6. Fontsize = "64"
  7. Click = "button_click"
  8. Margin = "0, 12, 0, 0"/>
  9. </GRID>

 

Write the Click Event code.

[CSHARP]View plaincopyprint?

  1. Private void button_click (Object sender, routedeventargs E)
  2. {
  3. Microsoft. Phone. Tasks. smscomposetask SMS = new Microsoft. Phone. Tasks. smscomposetask ();
  4. SMS. To = "13672265138 ";
  5. SMS. Body = "Hello, can I have fried beef at noon today? ";
  6. SMS. Show ();
  7. }

 

Press F5 and then click the button to open the text message page.

 

Look at the "output" window. At this time, we can see that the deactivated event has occurred, because the program has not exited, but is only put in the background.

 

Then, click "return" of the simulator and return it to our program. Let's look at the output window.

 

At this time, the activated event occurs.

 

OK. Let's blow the cowhide here today.

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.