Share via


UserActivityChannel.GetSessionHistoryItemsForUserActivityAsync Method

Definition

Gets the session history for a user activity.

public:
 virtual IAsyncOperation<IVector<UserActivitySessionHistoryItem ^> ^> ^ GetSessionHistoryItemsForUserActivityAsync(Platform::String ^ activityId, DateTime startTime) = GetSessionHistoryItemsForUserActivityAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<IVector<UserActivitySessionHistoryItem>> GetSessionHistoryItemsForUserActivityAsync(winrt::hstring const& activityId, DateTime const& startTime);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<IList<UserActivitySessionHistoryItem>> GetSessionHistoryItemsForUserActivityAsync(string activityId, System.DateTimeOffset startTime);
function getSessionHistoryItemsForUserActivityAsync(activityId, startTime)
Public Function GetSessionHistoryItemsForUserActivityAsync (activityId As String, startTime As DateTimeOffset) As IAsyncOperation(Of IList(Of UserActivitySessionHistoryItem))

Parameters

activityId
String

Platform::String

winrt::hstring

Identifies the user activity to get session history for.

startTime
DateTime DateTimeOffset

Get user activity sessions that were active between startTime and now.

Returns

A list of user activity session objects that were active during the specified time for the specified user activity.

Attributes

Windows requirements

Device family
Windows 10, version 1803 (introduced in 10.0.17134.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v6.0)

Examples

private async void GetMostRecentActivity()
{
    UserActivityChannel channel = UserActivityChannel.GetDefault();

    // Gets the 10 most recently engaged UserActivity objects, sorted by engagement EndTime (null EndTimes sort first)
    IList<UserActivitySessionHistoryItem> recentActivity = await channel. GetRecentUserActivitiesAsync(maxUniqueActivities: 10);

    foreach (var activity in recentActivity)
    {
        var engagements = await channel.GetSessionHistoryItemsForUserActivityAsync(activity.UserActivity.ActivityId, new DateTimeOffset(DateTime.Now, TimeSpan.FromDays(1)));

        long totalEngagementTime = 0;
        foreach(var e in engagements)
        {
            if (e.EndTime != null) // EndTime may be null for active UserActivities
            {
                totalEngagementTime += e.EndTime.Value.Ticks - e.StartTime.Ticks);
            }
            // App specific code to display the activity engagement time
        }
    }
}

Applies to