Microsoft in a new blog post on the Windows 8 app developer blog has posted detailed information about the app lifecycle of Windows 8 apps. If you had time to test the Windows 8 Developer Preview or Consumer Preview, you have probably noticed that apps get suspended when you are switching to another app or screen, and not terminated right away. You have probably noticed that apps do not have visible close buttons, or window controls at all displayed that let Windows 8 users terminate the app directly.
Microsoft’s focus was threefold. The company wanted to keep apps responsive, preserve battery life and provide consistent performance.
Metro style apps are all about full-screen, immersive experiences. As such, the new lifecycle model in Windows 8 focuses on the apps in the foreground, ensuring that the experience the user is actively engaged and gets the full power of the device. In this post, I’ll walk you through the new states of the lifecycle model and what you need to do to make your app great.
Metro style apps are always in one of the four lifecycles:
- not running
The diagram highlights the the three main lifecycles, and the state changes that move between them. Microsoft notes that apps will likely move between running and suspended states quite often as users switch between apps.
In general, Metro style apps stop running when the user switches to another app. Windows suspends your app when it is not in the foreground. When your app is suspended, it is frozen in memory. It can’t run in this state, but Windows can instantly resume it when the user returns to it. In this way, Windows gives the foreground app better use of system resources and ensures apps in the background can’t drain the user’s battery.
Apps are suspended a few seconds after a user has switched to another app or the desktop. This is done to enable quick switching back to the app.
When your app is resumed, it continues from the state that it was in when Windows suspended it. To be specific: app data and state are kept in memory while the app is suspended, so when it’s resumed, everything is as it was when the app was suspended. You don’t need to restore any saved data explicitly when receiving the resuming event.
Activation is all about how your app gets launched. It serves many purposes in a Metro style app. For more details on how you can use Metro style app activation to handle contracts, see our earlier post, Activating Windows 8 contracts in your app. Here we focus on how you can use activation to restore previously saved data in the case that Windows terminated your app and then the user relaunched it.
The blog post offers code examples and tips on how to create a great app lifetime experience. Developers find valuable information there that help them write better apps for the Windows 8 operating system. Still, it offers interesting tidbits for tech savvy Windows 8 users as well who want to know more about the inner workings of the operating system. (via)