Share via


UserActivitySessionHistoryItem Class

Definition

Provides the start and end time that a user was engaged in a particular activity.

public ref class UserActivitySessionHistoryItem sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 393216)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class UserActivitySessionHistoryItem final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 393216)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class UserActivitySessionHistoryItem final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 393216)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class UserActivitySessionHistoryItem
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 393216)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class UserActivitySessionHistoryItem
Public NotInheritable Class UserActivitySessionHistoryItem
Inheritance
Object Platform::Object IInspectable UserActivitySessionHistoryItem
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
        }
    }
}

Remarks

Many applications provide most-recently-used (MRU) lists. This class provides start and end time information about a UserActivity so that you can provide a similar experience for user activities.

Properties

EndTime

Get the time when the user stopped engaging in the UserActivity associated with this UserActivitySessionHistoryItem.

StartTime

Get the time when the user started engaging in the UserActivity associated with this UserActivitySessionHistoryItem.

UserActivity

Gets the UserActivity associated with this UserActivitySessionHistoryItem.

Applies to