Author:
Yochay
In the previous article
. I learned about three of the four events. We introduced the launching, closing, and deactivated events of the program. Now it's time to look at the last event, which is activated. If you want to use the Code provided in this article, you can download it here
.
How can I continue the debugging session of a tombstone application? -- Master activated events
Do you still remember I promise to talk about the function of the Return key? Now I want to fulfill it.However, read these steps and precautions before you proceed.
- In Visual Studio, start a new debugging session with the simple program we created in the previous article.
- Click Next to navigate to the second page of the program.
- Press the Windows key.
- The simulator returns to the starting interface, and you can see the following picture in the output window of Visual Studio:
As you can see, we started a new instance, so the launching event of the application was triggered. Then the first page (default) of the application is started, so you will see the tracing information on the home page. When you press the next button, the program will navigate to the second page, as you can see from the tracking information on the details page. Finally, when you press the Windows key, the program will be disabled and displayed in the tracking information. The simulator also returns to the starting interface.
Note: Do not disable the simulator or change the code,
Otherwise, an instance of a new program will be started, which is not what we want.
- In the Windows Phone simulator, you should be able to see the start interface and press the return key.
- The screen of the simulator turns black as if it was waiting for something to happen. What's the problem? In fact, this is the design in the current beta tool. The screen turns black when you return to the debugger to continue debugging the program.Not restarted
.
- Restart
Debugger andContinue
Debug sessions, switch to Visual Studio, and press F5 (or use any method to start your debugger ). The debugger will be appended to the corresponding program instance, the simulator continues to activate the program, and thenActivated
The event is triggered, as you can see:
Note:
: Whether the process succeeds depends on oneTime Limit
If the time for re-loading the program exceeds10 seconds
The simulator terminates the program. So you must hurry up. Also, you should not add any breakpoints to the activated event. According to the design guide of Windows Phone, your application interface should be loaded within 10 seconds, and because the activated event is handled before the homepage constructor, therefore, the interface is not displayed when you enter the activated event for debugging.
Now that you know what to do, follow the steps above to reactivate your application and restore it from the tombstone state. You will notice that Visual Studio has started a "new session" (because the instance of the first program has been terminated ). However, the first line of this trail information shows the activated event instead of the launching event. After the activated event, the next line in the input window shows the constructor on the details page instead of the default page of the program. If you observe the simulator, you will see that the program returns the correct page, which is the page you browsed before pressing the Windows key.
You see, you have personally experienced how a program changes to a tombstone state and how it is revived.
Note:
: When your application returns from the tombstone status, it is a new instance of the program. Although this is the case, you cannot see the launching event, therefore, you cannot see the launching trace information in the input window. The launching event and activated event areMutually Exclusive
, So in the same running of the application, youWill not see them appear at the same time
.
Important:
Launching, deactivated, activated, and closing events are application-level events. They will always be triggered (unless you remove --But you shouldn't do this.
). If your application has any common work to handle, these events are the right tools (as we will mention later ).
As you can see, the application can return to any page from the tombstone status, so you cannot guarantee which page will be loaded earlier than others.
The most important thing about the tombstone mechanism is to remember users.You can choose not to return to the original application
, SoYour program may not be reactivated
. The user may restart the application on the starting interface (instead of using the return key ).Start a new instance of the program
. This is the issue of the launching event or the activated event. Or the user starts several applications, which makes the application in the tombstone state more and more down in the back-to-stack position so that the return key cannot be reached. In this case, you need to save any data you want to restore. Of course, whether or not to access the data in the program depends entirely on you and your job responsibilities. This is also the topic of our next article. Now let's take a look at the figure below, from the Windows Phone development documentation.
This should help you understand the relationship between different events.
Now, you should understand the meanings and functions of the -- launching, deactivated, closing, and activated events involved in Windows Phone applications. This is just the beginning, because we have many additional topics to discuss to thoroughly understand the execution model and how to make full use of it in your program. In the next article, you will learn how to save your page status information and under what situations you need to save and load the data.
Sample Code can be downloaded here
This download.
Windows Phone 7 developer training kit
Contains a dedicated Windows Phone application Lifecycle
.
The msdn document also contains a topic Windows Phone execution model Overview
.
View the original text.
The purpose of this article is to learn and exchange, and the copyright is owned by the original author.