开发者

Does WP7 save variables on close?

开发者 https://www.devze.com 2023-03-14 05:38 出处:网络
When my app closes will the values i have set s开发者_开发技巧till be there when I re open it?

When my app closes will the values i have set s开发者_开发技巧till be there when I re open it? Or is there a way to save them somewhere?


No they won't,

When you jump-out from the application, application will go to a state called TombStoned, it is your responsibility to store and retrieve useful page elements.

In order to do this, you need to store information on the following event on your page:

public override void OnNavigatedFrom(...)
{
    State["XXX"] = txtName.Text; // save your data on page state (keep it low in size!)
}

the same way you need to retrieve your data on the following event

public override void OnNavigatedTo(...)
{
    txtName.Text = State["XXX"]; // read your data from page state
    // also check if state has any entry with this key
}

If you need to store application level data, you need to do it in your App.xaml.cs in the following events:

public override void OnDeactivated(...)
{
    // Store in IsolatedStorageSettings
}

public override void OnActivated(...)
{
    // Read from IsolatedStorageSettings
}

For more details about Tombstoning read the following article:

http://www.scottlogic.co.uk/blog/colin/2011/05/a-simple-windows-phone-7-mvvm-tombstoning-example/


When you app closes, all data information is lost unless you save it somewhere. For transient data, like page state things (e.g. textboxes, checkbox etc..), you can use PhoneApplicationPage.State. If you need to store data permanently so that it's there the next time the user launches the app, you should store it in Isolated Storage. You can learn more about tombstoning and when you should store states in this MSDN page.

There is also a helper library on CodePlex called Tombstone Helper which will make it easier to store data during tombstoning.

0

精彩评论

暂无评论...
验证码 换一张
取 消