UserActivity UserActivity UserActivity UserActivity Class


A UserActivity is created by an app during its execution to notify the system of a user work stream that can be continued on another device, or at another time on the same device. It provides information about a task the user is engaged in.

public : sealed class UserActivity : IUserActivity
public sealed class UserActivity : IUserActivity
Public NotInheritable Class UserActivity Implements IUserActivity
// This class does not provide a public constructor.
Windows 10 requirements
Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)


A UserActivity encapsulates a user's task that can be continued at a later time, and potentially on a different device. For example, a mail app could create a UserActivity when the user starts creating a new email message. The user could pause working on the email and then work on it later on the same machine, or even another device.


ActivationUri ActivationUri ActivationUri ActivationUri

Gets and sets the activation Uniform Resource Identifier (URI).

public : Uri ActivationUri { get; set; }
public Uri ActivationUri { get; set; }
Public ReadWrite Property ActivationUri As Uri
var uri = userActivity.activationUri;
userActivity.activationUri = uri;
Uri Uri Uri Uri

The activation URI.


If a UserActivity represented reading an RSS reader article, for example, you could set the activation URI to the URI of the article so that when the user taps on the user activity tile in the Timeline, the RSS reader app is reactivated:

userActivity.ActivationUri = new Uri("rss-reader:article?" + article.Link);


The activation URI provides a cross-platform activation context for the activity.

ActivityId ActivityId ActivityId ActivityId

Gets the activity ID that was assigned to this UserActivity when it was created.

public : Platform::String ActivityId { get; }
public string ActivityId { get; }
Public ReadOnly Property ActivityId As string
var string = userActivity.activityId;
Platform::String string string string

The activity ID.

ContentInfo ContentInfo ContentInfo ContentInfo

Gets or sets the content information object for this user activity.

public : IUserActivityContentInfo ContentInfo { get; set; }
public IUserActivityContentInfo ContentInfo { get; set; }
Public ReadWrite Property ContentInfo As IUserActivityContentInfo
var iUserActivityContentInfo = userActivity.contentInfo;
userActivity.contentInfo = iUserActivityContentInfo;


The content information inside the UserActivityContentInfo object is stored in the JSON format.

ContentType ContentType ContentType ContentType

Gets and sets the MIME (Multipurpose Internet Mail Extensions) type of the content stored at UserActivity.ContentUri. For example, "text/plain".

public : Platform::String ContentType { get; set; }
public string ContentType { get; set; }
Public ReadWrite Property ContentType As string
var string = userActivity.contentType;
userActivity.contentType = string;
Platform::String string string string

The content type.

ContentUri ContentUri ContentUri ContentUri

Gets and sets the content Uniform Resource Identifier (URI) of the image that will be used to represent the activity on another device.

public : Uri ContentUri { get; set; }
public Uri ContentUri { get; set; }
Public ReadWrite Property ContentUri As Uri
var uri = userActivity.contentUri;
userActivity.contentUri = uri;
Uri Uri Uri Uri

The content URI.


One use for a content URI is if you don't have a website for the app but you have content that could be viewed, instead.

FallbackUri FallbackUri FallbackUri FallbackUri

Gets and sets the fallback Uniform Resource Identifier (URI) to use if there is no handler for the activation URI.

public : Uri FallbackUri { get; set; }
public Uri FallbackUri { get; set; }
Public ReadWrite Property FallbackUri As Uri
var uri = userActivity.fallbackUri;
userActivity.fallbackUri = uri;
Uri Uri Uri Uri

The fallback URI.


This should be a http or https URI that the system can fall back to if there is no handler for the activation URI.

State State State State

Gets the state (Published or New) of this UserActivity.

public : UserActivityState State { get; }
public UserActivityState State { get; }
Public ReadOnly Property State As UserActivityState
var userActivityState = userActivity.state;


UserActivity userActivity = await channel.GetOrCreateUserActivityAsync(activityId);

//if it's a new UserActivity associate metadata with it
if (userActivity.State == UserActivityState.New)
    //required fields, SaveAsync() throws ArgumentNullException if not set
    userActivity.ActivationUri = new Uri("rss-reader:article?" + article.Link);
    userActivity.DisplayText = article.Title; //used for details tile text

    //optional fields
    userActivity.FallbackUri = article.Link;

    //we don't have a website for the app, but the article can be viewed in a browser
    userActivity.ContentUri = article.Link;

    userActivity.VisualElements.Description = article.Summary; //optional

    userActivity.ContentInfo = UserActivityContentInfo.FromJson(
        ""@context"": """",
        ""@type"": ""Article"",
        ""author"": ""John Doe"",
        ""name"": ""How to Tie a Reef Knot""
    await userActivity.SaveAsync();


Knowing that a UserActivity is New versus Published can be used to determine whether GetOrCreateUserActivityAsync() returned a newly created UserActivity or one that had been previously created.

VisualElements VisualElements VisualElements VisualElements

Gets information that can be used for the details tile for this activity.

public : UserActivityVisualElements VisualElements { get; }
public UserActivityVisualElements VisualElements { get; }
Public ReadOnly Property VisualElements As UserActivityVisualElements
var userActivityVisualElements = userActivity.visualElements;
UserActivityVisualElements UserActivityVisualElements UserActivityVisualElements UserActivityVisualElements

The description, icon, and so on, associated with this UserActivity.


CreateSession() CreateSession() CreateSession() CreateSession()

Creates a UserActivitySession that this user activity will be associated with. You must call this method on the UI thread.

public : UserActivitySession CreateSession()
public UserActivitySession CreateSession()
Public Function CreateSession() As UserActivitySession
var userActivitySession = userActivity.createSession();


When a UserActivity is associated with a UserActivitySession, it indicates that the user is currently engaged in the activity.

SaveAsync() SaveAsync() SaveAsync() SaveAsync()

Publish the UserActivity.

public : IAsyncAction SaveAsync()
public IAsyncAction SaveAsync()
Public Function SaveAsync() As IAsyncAction
Windows.ApplicationModel.UserActivities.UserActivity.saveAsync().done( /* Your success and error handlers */ );

An asynchronous action that can be awaited.


UserActivity.DisplayText and UserActivity.ActivationUri must be set before calling SaveAsync() or the call will fail.

Saving a UserActivity converts its state to UserActivityState.Published