次の方法で共有


コンテンツの再起動を有効にする Recall

Recall アプリケーションのスナップショットは自動的に保存されますが、スナップショットの時点で UserActivity を指定しない限り、ユーザーはコンテンツに対して再起動できません。 これにより、 Recall はその時点で表示されていた内容に戻ってユーザーを起動できます。

ユーザー アクティビティ は、ユーザーがアプリ内で作業していた特定のものを指します。 たとえば、ユーザーがドキュメントを作成している場合、UserActivity はユーザーが書き込みを中断したドキュメント内の特定の場所を指す可能性があります。 ミュージックアプリを聴いている場合、UserActivity はユーザーが最後に聴いたプレイリストである可能性があります。 キャンバス上で描画する場合、UserActivity はユーザーが最後にマークを作成した場所である可能性があります。 つまり、ユーザーが実行していた操作を再開できるように、UserActivity はユーザーが戻ることのできる Windows アプリ内の目的地を表します。

ユーザー アクティビティのプッシュ

アプリのメイン コンテンツが変更されるたびに (ユーザーが別のメールを開いたり、別の Web ページを開いたりするなど)、システムが現在開いているコンテンツを認識できるように、新しい UserActivitySession を記録する必要があります。 Recall では、最新の UserActivity を保存したスナップショットに関連付け、アクティビティ内の ActivationUri を使用して、ユーザーがそのコンテンツに再起動できるようにします。

Recallを実行していない PC でも、すべての PC でユーザー アクティビティをプッシュすることをお勧めします。

UserActivitySession _previousSession;

private async Task OnContentChangedAsync()
{
    // Dispose of any previous session (which automatically logs the end of the interaction with that content)
    _previousSession?.Dispose();

    // Generate an identifier that uniquely maps to your new content.
    string id = "doc135.txt";

    // Create a new user activity that represents your new content
    var activity = await UserActivityChannel.GetDefault().GetOrCreateUserActivityAsync(id);

    // Populate the required properties
    activity.DisplayText = "doc135.txt";
    activity.ActivationUri = new Uri("my-app://docs/doc135.txt");

    // Save the activity
    await activity.SaveAsync();

    // And start a new session tracking the engagement with this new activity
    _previousSession = activity.CreateSession();
}

GetOrCreateUserActivityAsync メソッドは、常に最新バージョンの Windows で新しいアクティビティを返します。 以前に保存したアクティビティを取得する機能が削除され、Windows はアプリの以前のアクティビティを取得できるように保存しなくなりました。

省略可能: 要求されたイベントの処理

アクティビティのプッシュに加えて、アプリは UserActivityRequested イベントを実装することを選択できます。このイベントは、Windows が起動して、アプリからの最新のアクティビティを確実に持っていることを確認できます。

public void OnLaunched()
{
    UserActivityRequestManager.GetForCurrentView().UserActivityRequested += UserActivityRequested;
}

private async void UserActivityRequested(
    Windows.ApplicationModel.UserActivities.UserActivityRequestManager sender,
    Windows.ApplicationModel.UserActivities.UserActivityRequestedEventArgs args)
{
    // Start a deferral so you can use async code
    var deferral = args.GetDeferral();

    try
    {
        // Generate an identifier that uniquely maps to your current content.
        string id = "doc135.txt";

        // Create a user activity that represents your current content
        var activity = await UserActivityChannel.GetDefault().GetOrCreateUserActivityAsync(id);

        // Populate the required properties
        activity.DisplayText = "doc135.txt";
        activity.ActivationUri = new Uri("my-app://docs/doc135.txt");

        // And return the activity to the event handler
        args.Request.SetUserActivity(activity);
    }

    finally
    {
        // And complete the deferral
        deferral.Complete();
    }
}