Saving the emulator state between runs was one of the feature needed for the Windows Phone emulator, but till now it is not officially supported. It even makes more sense now when the Windows Phone 8 emulator is a full working operating system and not a trimmed one like Windows Phone 7/7.5 was. You could configure an email account, personalize the start screen, install some applications, install certificates or even save the state of an application that requires a lot of data to synchronize before the actual debugging and have everything ready the next time you start the emulator.
Today I was trying to run the Windows Phone 8 emulator on a Parallels 8 machine using this post because I hate Windows 8 performance in Bootcamp (the disk access is crappy and the UEFI mode still needs drivers for sound, video and a way to enable Hyper-V). I observed that the first time you run an Windows Phone emulator it took more than 40 seconds to start. The reason is that the SDK creates a new Virtual Machine in Hyper-V and saves a "clean" snapshot of it.
On every subsequent run of that emulator the XDE automatically starts the virtual machine and immediately applies the snapshot (or starts the virtual machine from the snapshot directly). What caught my attention was the name of the snapshot for each virtual machine:
- Emulator 720P - snapshot.720x1280.1024
- Emulator WVGA 512MB - snapshot.480x800.512
- Emulator WVGA - snapshot.480x800.1024
- Emulator WXGA - snapshot.768x1280.1024
I tried and messed up the names and observed that XDE, if it doesn't see a certain Snapshot, it starts the Virtual Machine and creates a new snapshot with the required name. So in order to save the state it would be enough to alter/change the snapshot XDE uses to start the virtual machine.
First we need to start the emulator we want to personalize (in this post i will mess up the 512 WVGA emulator). This can be done in two ways:
- From Visual Studio by running a program on that emulator or from Application Deployment (the emulator is easy to personalize because you can zoom the content and you have the hardware buttons but will require a subsequent reset of the Virtual Machine from Hyper-V)
- From Hyper-V manager by starting the Emulator WVGA 512MB virtual machine and applying the saved snapshot for a fast start. After the machine starts you will have to connect to it:
Once connected to the emulator/virtual machine you can personalize/modify the way you want it to be. If you connected using Hyper-V these keyboard shortcuts will prove helpful (they also work in the emulator):
- F1 - the same as pressing the back button
- F2 – the same as pressing the home button
- PageUp - enables physical keyboard and minimizes the software keyboard
- PageDown – disables physical keyboard and maximizes the software keyboard
- F9 - volume up
- F10 - volume down
- F7 – invoke camera
- F3 – invoke Bing search
If you want/need to install some xap's you can use Application Deployment with the Emulator.
When you've reached the desired state go to the Hyper-V manager, select the Virtual machine that you are personalizing and hit Snapshot. This will create a new Snapshot(save state for the emulator).
If you've started the emulator from Visual Studio or Application Deployment App before you create the snapshot you will have to connect to the Virtual Machine from Hyper-V and from the menu Action select Reset (this will clean the ports used for debugging and the state you will save will be usable for Visual Studio and XDE).
After saving the new state the only thing you have to do is to rename the snapshot with the same name of the parent snapshot and delete the parent by right-clicking on it and select Delete Snapshot (DO NOT select Delete Snapshot Subtree).
You are now ready to go: Turn Off the virtual machine from Hyper-V and try it from Visual Studio. Everything should work. If it doesn't it means that the state has some ports that Visual Studio uses still opened and in this case you will have to connect to the Virtual Machine from Hyper-V, Reset the machine from Action and save a new Snapshot.
My personalized emulator looks like this:
If you want to get back to an "unaltered" state just delete the snapshot of the corresponding Virtual Machine from Hyper-V Manager.
Hope saving the emulator state will help you in some scenarios.