Tombstoning and Task Switching - Day 3 - Part 8
- Posted: Nov 11, 2010 at 6:08 PM
- 18,651 Views
- 12 Comments
Download
How do I download the videos?
- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”
Why should I download videos from Channel9?
- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!
Which version should I choose?
- If you want to view the video on your PC, Xbox or Media Center, download the High Quality WMV file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality WMV file.
- If you have a Zune, WP7, iPhone, iPad, or iPod device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.
Right click “Save as…”
- High Quality WMV (PC, Xbox, MCE)
- MP3 (Audio only)
- MP4 (iPod, Zune HD)
- Mid Quality WMV (Lo-band, Mobile)
How does your application respond when a user clicks the Start button or Back button on Windows Phone 7? In this video, Bob explains the difference between the Launched, Activated, Closed, and Deactivated events, how your application can be notified via event handlers in the App.xaml.cs code-behind file, and how to take that opportunity to save the current state of the application. Then, once the user has re-launched the applications, the state information can be retrieved and the state of the application from the previous session can be restored. Bob also explains how a special feature of Isolated Storage called IsolatedStorageSettings can provide an easy way to save name / value pair information without having to create and access a text file.
Comment on the Post
Already have a Channel 9 account? Please sign in
Follow the Discussion
Does App.xaml.cs.SaveState() also need to use TryGetValue, since, the first time it is run, if we leave the page or hit start before we change the TextBox, there is nothing in the property bag and the access fails with an exception?
The sequence of Load, Activate, Deactivate, and Close calls was not obvious at first. And the fact that the debugger keeps dropping out makes it tough to follow. A useful extension to this module would be to record each of these events (WHEN it occurred) in the string we are saving.
These changes would go in App.xaml.cs:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
LoadState("L");
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
LoadState("A");
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
SaveState("D");
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
SaveState("C");
}
And then:
private void SaveState(string when)
{
PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (phoneAppService.State.ContainsKey("MyValue"))
{
settings["MyValue"] = phoneAppService.State["MyValue"] + " " + when + " ";
}
else
{
settings["MyValue"] = when + " ";
}
}
private void LoadState(string when)
{
PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
if (settings.Contains("MyValue"))
{
phoneAppService.State["MyValue"] = settings["MyValue"] + " " + when + " ";
}
else
{
phoneAppService.State["MyValue"] = when + " ";
}
}
David
12:12: It is unnecessary to condition 'TryGetValue' with 'ContainsKey' ('TryGetValue' combines 'ContainsKey' and 'Item' getter, see http://msdn.microsoft.com/en-us/library/bb347013(VS.95).aspx).
great video, thanks.
A very useful video but I have a question: I got the impression from the diagram on the link
http://msdn.microsoft.com/en-us/library/ff817008(v=VS.92).aspx">http://msdn.microsoft.com/en-us/library/ff817008(v=VS.92).aspx which is part of the instructions for submission that we are not "allowed" to run any code in the lauch event handler. This is the best place to run the LoadState() code as it is only done once. Are you able to clarify?
Dani.
Very good! very simple and useful. Thanks a lot!
I have tried this with the Simple Note application, which is the homework of day 3.
But whenever I press the start button, the app crashes and an error appears in the c# code.
I have tried the code of dwrogers, and it doesn't do anything at all.
So, is there any solution, as this is vital to me?.
Got this to work on my second attempt! One of the harder lessons so far.
I think I've done exactly as Bob instructed, but when I type something in the text box, tap the Windows key and then return to the application, the text has gone. Same with the Back key. Can't figure out what the difference could be.
Hi, here is the way how to have the testing device always set to Emulator.
http://www.pchenry.com/Home/tabid/36/EntryId/412/Tired-of-ALWAYS-having-to-change-to-the-WP7-emulator-in-Visual-Studio.aspx
I came across to the same problem of Vesku (May 23, 2011 at 5:22 AM) and I (not easily) solved it. Shortly, the line of code
if (phoneAppService.State.ContainsKey("MyValue"))
in the LoadState() method should be commented (or deleted). This solves the problem. I know the app in the video works but it can be easily a bug that has been corrected with the newest releases of Silverlight or whatsoever.
Remove this comment
Remove this thread
close