Local folder best practices for Windows Phone 8
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
This topic provides best practices and general information for using the local folder (previously known as isolated storage) in Windows Phone.
This topic contains the following sections.
- Updating an app
- Uninstalling an app
- Managing space in the local folder
- Data synchronization
- Data-bound objects and the IsolatedStorageSettings class
Updating an app
When an app is updated in the Store, its local folder is not touched or modified. It is your responsibility to make sure the data is migrated or transformed appropriately to work with the new version of the app.
Uninstalling an app
If an app is uninstalled, the data root and everything within the local folder, is deleted.
Windows Phone apps are not restricted to a particular quota. They should make careful use of storage based on their app scenario requirements.
Managing space in the local folder
Storage resources on a phone are limited. With the ability to download apps and media, and to sync data to the phone, storage space comes at a premium. When a Windows Phone has only 10 percent of its storage space remaining, the user receives a status notification. The user can then delete pictures, music, and apps in order to create the necessary storage space. However, this is not a desirable option from the user’s perspective.
Windows Phone apps do not have an imposed quota size because the requirements for each app’s scenario are different. Also, limiting the disk size on a per-app basis can result in unfriendly user scenarios. Therefore, apps should take care to store only what's necessary for subsequent launches of the app.
The following best practices provide techniques for making prudent use of storage space on a Windows Phone:
Temporary data and files: If your app creates any temporary data in the local folder, make sure that it is cleared when the data is no longer being used. This data can be in the form of media that has newer, modified copies. For example, Microsoft Internet Explorer manages a cache with a temporary files folder that can be cleared to free up more storage space. To follow this model in your app, consider creating a temporary cache folder that you can clear at regular intervals.
User-generated data: This can be photos from the camera app, or user-created files such as notes or documents.
If your app allows users to create data, they should have the option to delete the data that they create. An example is a photo app that exposes a list of photos that users can subsequently delete based on their preferences.
To reduce the storage footprint of your app, you can synchronize or archive data to the cloud and keep only the most relevant data. For example, Microsoft Outlook on Windows Phone keeps mail for only three days by default, and the rest is stored on the server. However, in your app, the user can modify this setting as necessary.
Application Data: Examples include a list of stores or shops managed by a shopping list application, or a list of words contained in a dictionary application. If your application sources data from the cloud and caches it locally, make sure that you recycle it based on what is most relevant.
To synchronize access to the local folder between different threads, we recommend using the Mutex class. A mutex grants exclusive access to a shared resource to only one thread. If one thread acquires a mutex, the second thread that wants to acquire that mutex is suspended until the first thread releases the mutex. For example, a mutex could be used to synchronize access to a folder between a Windows Phone app running in the foreground and a background agent.
Data-bound objects and the IsolatedStorageSettings class
When the user exits your application, Windows Phone automatically calls Save to save the IsolatedStorageSettings. If you have placed any data-bound objects in the IsolatedStorageSettings, they are saved when the user exits the application.