Blog Park client (Universal app) development essay-app roaming data (roaming)

Source: Internet
Author: User

When a user uses an app on multiple Windows devices, we want the user's settings and data to be shared among multiple users, such as articles in our new version of the collection. Typically, to do this, we might need to get a server or use a Web site like OneDrive to store files, but it's a bit too much for our small app, adding code and maintenance work. Using Windows Roaming at this time is a convenient option.

The so-called roaming data, which is described on MSDN:

Windows 8 can automatically transfer certain app data between user devices. Application developers no longer need to perform laborious work. Roaming app data provides an excellent app experience for end users using multiple devices, such as Office PCs and home tablets

When the Windows app is installed, it will provide its own user data store for app data such as settings and files (because Windows may use a different account to log on, so this storage needs to be separated by users), presumably in 4 categories, see MSDN.

Local

Data that exists on the current device will be backed up in the cloud.

Roaming

Data exists on all devices on which the user has installed the app.

Temporary

Data that can be deleted by the system at any time.

LocalCache

Persistent data exists only on the current device.

where roaming (roaming) is what we need, there are two types of data that can roam: settings and files. And we just have to be responsible for writing the content, the rest is controlled by the system (even after the network exception automatically retry, save us a lot of time and code AH).

Roaming settings:

The settings are the Key-value storage space provided by Windows, using the same methods and dictionaries, but you need to be aware of the types that can be stored, only support the most runtime (runtime) types, and don't think about custom types.

// for settings items that do not require synchronization, use the LocalSettings // Applicationdatacontainer local = Windows.Storage.ApplicationData.Current.LocalSettings; // need to synchronize the use of roamingsettings, the use of the two setting is the same Applicationdatacontainer roaming = windows.storage.applicationdata.current.roamingsettings;roaming. values["key"" roaming settings ";
Roaming files:

When the settings do not meet the requirements, we can write the content to the file and store it in the roaming folder.

// Roaming folders var roamingfolder = Windows.Storage.ApplicationData.Current.RoamingFolder; // create a file within the roaming folder, var await roamingfolder.createfileasync (filename, creationcollisionoption.openifexists); // Write Content await  " content that needs to be synced ");

The above is the use of roaming code, so long as users use the same account to log on the device, and installed the same version of the application (note: Must be the same version), then the data will be synchronized with the system.

The effect is as follows:

Windows side:

Windows Phone side:

Although it is convenient to roam, its use is limited.

There is a size limit for app data roaming in Windows (it should be 100KB, although no specific values are explicitly given on MSDN, but this value should be device-independent, and even if not, we should choose the smallest as a benchmark. ), can be obtained by using Windows.Storage.ApplicationData.Current.RoamingStorageQuota, in kilobytes.

The students who use simulator testing need to be aware that the value returned on the simulator is 0 ...

If this limit is exceeded, the data will not be roamed. Because of this limitation, we need to carefully select the contents of the storage (hope to improve this limit later, a little less than the use AH. ), try to select the necessary application settings and small files.

Because the roaming itself is not designed in time to synchronize, so it will result in inconsistent data of the application, that is, you save a file on the phone, not necessarily be immediately synchronized to other devices, this time is determined by the system (also related to the network), so the students can bypass the time requirements. For this MSDN there is a detailed description:

Windows roams app data randomly and does not guarantee instant synchronization. Roaming can be significantly delayed if the user is offline or in a high-latency network. Do not build a UI that requires immediate synchronization. If your app frequently changes information (for example, the latest location in a song or movie), do not use the Roaming app Data feature for this data. Instead, choose a representation that is less frequent but still provides a good user experience – for example, the currently playing song, the current movie chapter, and so on.

Our published apps and code can be found below:

Windows Phone Store App Link:

http://www.windowsphone.com/zh-cn/store/app/Blog Park-UAP/500F08F0-5BE8-4723-AFF9-A397BEEE52FC

Windows Store App Link:

http://apps.microsoft.com/windows/zh-cn/app/c76b99a0-9abd-4a4e-86f0-b29bfcc51059

GitHub Open Source Link:

Https://github.com/MS-UAP/cnblogs-UAP

MSDN Sample Code:

Https://code.msdn.microsoft.com/CNBlogs-Client-Universal-9c9692d1

Blog Park client (Universal app) development essay-app roaming data (roaming)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.