Friday 7 December 2012

Windows 8 Apps : Understanding states of an app

In this article I will try to bring out my understanding on how Windows 8 Apps state work. This is an introductory article and the details on each state will be talked on in other articles in this series.

An app in its lifetime changes its states from Not running to running , running to suspended , suspended back to running (through resume.)

An app is in the Not Running State in any of the following scenarios:
a. App is installed/deployed.
b. App is launched.
c. App is suspended.

An app is in the Running state when:
a. It is activated , either manually or through some other process.

An app is in the Suspended state when:
a. User switches from one app to the other.
b. Windows enters into low power state.

During its lifecycle the app continuously toggles between theses three states.


Let us see what exactly happens within an application.

A user logs on to windows app store:

Selects the appropriate app to download to his device(PC, laptops, tablet, mobile) and downloads it.


 
 

 
 
 
 
 
The app consists of a manifest and file(s) .
 


 
 
Manifest in app
a. Contains the metadata for the application
b. Describes the capabilities of the app
c. Is used by the os while installing/uninstalling the app.
 
What do we mean by 'capabilities of the app' , basically capabilities of the app will say whether the app has internet capabilities , access to resources on the device , connection with other devices etc.

 Now that the app is installed on user's device what happens next??
 
After the deployment , User clicks on the app to launch it.
 
Whenever user launches the app , the app shows a splash screen. Splash screen is shown to the user on behave of the Windows as the app readies itself to be presented.
 
 What does a splash screen do?

A splash screen basically:
a. Makes the UI ready.
b. Registers Event Handlers.
c. Registers Custom Controls.

You need to handle the splash screen and app activation events carefully. Because if the app is not activated within a small time period(~15 seconds) , the OS may kill your app . To be on App store the app must get activated within 2-3 seconds. So, understanding of the splash screen and app activation is very important. We will discuss this in next blogs.

Best practices to add splash screens.

Let, see here what happens after splash screen is displayed and apps completes activation.


 After the app is completes activation.
 a. App enter into 'running' state.
 b. Splash screen is torned down.(are the objects still alive ?? ideally no.)

Now, the app is activated and from not running state it enters into the running state.


 An app can be activated either through manual launch or whenever the app is being called by device , or by any other processes like print , search etc.

Whenever user launches another app or toggles to some other app, the currently activated app enters the suspended state.

The application can also get into suspended state whenever windows enters low battery mode.

In suspended state the app:
a. Saves relevant app data
b. Saves relevant user data
c. Releases all the handlers.(if it has any)
d. Release all the resources its using.(if any)

Windows keeps the suspended apps in memory so that whenever user switches back , the app launches without hiccups.



In case the app is not resumed after a specific time (5~10 sec) , windows terminates the app. Even during the terminated state the app data/user data are stored. So, whenever the user wants to resume the app back/windows recovers from low battery , the app loads itself from the terminated state.
 If there are a lot of applications in the memory which are in suspended state , windows releases the memory by changing the state of the app to Not Running state.

Whenever the user closes the app the app state changes to Not running.

In next articles we will see more into the details of how to exploit these three states programmatically.

 

No comments:

Post a Comment