Application switching in Windows Phone 7

Source: Internet
Author: User

Fixed:

Different from the desktop operating system, Window phone Application not supportedProgramRun in the background. This is to prevent multiple applications from competing for limited mobile phone resources, thus avoiding rapid reduction in processing speed and battery power. Here, Windows Phone 7 provides a new concept, Tombstoning. In Windows Phone , Because the user leaves the current application, the operating system suspends the application, but saves the instant status for restoration at any time. This is called Tombstoning.

For more information, refer to tombstoning in Windows Phone 7.

Like windows multi-task, you can also Switch Applications on Windows Phone 7. Note that you do not close the program, but switch. To close a program, it completely removes the program from the memory, but switches the program, the program is only deactivate.

Here we will not specifically discuss what Windows Phone 7 did when it was started, what it did when it was disabled, and what it did when it switched the task, this article only saves the state of the application when switching tasks by using phoneapplicationservice. The state of the application is saved the next time you open the application. As for the previous questions, I have time to write a blog to share with you.

Phoneapplicationservice class

The phoneapplicationservice class located in Microsoft. Phone. Shell provides a way to obtain application lifecycle information. This information includes the application idle status and Management of the status when the application is activated or not.

From msdn:

The phoneapplicationservice class provides access to various aspects of the application's life time. This includes des management of the application's idle behavior and management of the application's state when it becomes active or inactive.

Let's take a look at the structure of this class.CodeThe current and State attributes of the class will be used. Other interested friends can study them on their own.

Current can obtain the phoneapplicationservice instance of the current application.

State is an idictionary based on key-value pairs, used to save the state of the current application you want to save

Steps

1. Create a Windows Phone 7 Application, add a textbox to the grid named contentpanel, name it tbusername, and clear the text attribute.

2. Double-click tbusername and navigate to the back-end code to compile the textchanged event of tbusername, as shown in

3. Edit the application startup event. The Code is as follows:

We can run the program first, enter some letters in the input box, and press the back key or start key. When we enter the application again, the input box is still empty.

4. Write the following code in APP. XAML. CS to set the status and load status.

5. Call the Loading Method in application_launching and application_activated. Call the setting status method in application_deactivated and application_closing.

6. Then, let's try again the operation in step 3. You will find that when you enter the application again, the content you just entered is still in the input box.

Source codeDownload:

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.