You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: uwp/launch-resume/how-to-launch-an-app-for-results.md
+71-7Lines changed: 71 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,9 @@ ms.date: 02/08/2017
6
6
ms.topic: article
7
7
keywords: windows 10, uwp
8
8
ms.localizationpriority: medium
9
+
dev_langs:
10
+
- csharp
11
+
- cppwinrt
9
12
---
10
13
# Launch an app for results
11
14
@@ -59,7 +62,7 @@ If this method does not already exist in the launched app, create it within the
59
62
60
63
In an app that lets you pick your friends in a social network, this function could be where you open the people-picker page. In this next example, a page named **LaunchedForResultsPage** is displayed when the app is activated for results. Ensure that the **using** statement is included at the top of the file.
Because the protocol extension in the Package.appxmanifest file specifies **ReturnResults** as **always**, the code just shown can cast `args` directly to [**ProtocolForResultsActivatedEventArgs**](/uwp/api/Windows.ApplicationModel.Activation.ProtocolForResultsActivatedEventArgs) with confidence that only **ProtocolForResultsActivatedEventArgs** will be sent to **OnActivated** for this app. If your app can be activated in ways other than launching for results, you can check whether [**IActivatedEventArgs.Kind**](/uwp/api/windows.applicationmodel.activation.iactivatedeventargs.kind) property returns [**ActivationKind.ProtocolForResults**](/uwp/api/Windows.ApplicationModel.Activation.ActivationKind) to tell whether the app was launched for results.
86
118
87
119
## Step 3: Add a ProtocolForResultsOperation field to the app you launch for results
You'll use the [**ProtocolForResultsOperation**](/uwp/api/windows.applicationmodel.activation.protocolforresultsactivatedeventargs.protocolforresultsoperation) field to signal when the launched app is ready to return the result to the calling app. In this example, the field is added to the **LaunchedForResultsPage** class because you'll complete the launch-for-results operation from that page and will need access to it.
95
131
96
132
## Step 4: Override OnNavigatedTo() in the app you launch for results
97
133
98
134
99
135
Override the [**OnNavigatedTo**](/uwp/api/windows.ui.xaml.controls.page.onnavigatedto) method on the page that you'll display when your app is launched for results. If this method does not already exist, create it within the class for the page defined in <pagename>.xaml.cs. Ensure that the following **using** statement is included at the top of the file:
The [**NavigationEventArgs**](/uwp/api/Windows.UI.Xaml.Navigation.NavigationEventArgs) object in the [**OnNavigatedTo**](/uwp/api/windows.ui.xaml.controls.page.onnavigatedto) method contains the data passed from the calling app. The data may not exceed 100KB and is stored in a [**ValueSet**](/uwp/api/Windows.Foundation.Collections.ValueSet) object.
106
146
107
147
In this example code, the launched app expects the data sent from the calling app to be in a [**ValueSet**](/uwp/api/Windows.Foundation.Collections.ValueSet) under a key named **TestData**, because that's what the example's calling app is coded to send.
## Step 5: Write code to return data to the calling app
128
186
129
187
130
188
In the launched app, use [**ProtocolForResultsOperation**](/uwp/api/windows.applicationmodel.activation.protocolforresultsactivatedeventargs.protocolforresultsoperation) to return data to the calling app. In this example code, a [**ValueSet**](/uwp/api/Windows.Foundation.Collections.ValueSet) object is created that contains the value to return to the calling app. The **ProtocolForResultsOperation** field is then used to send the value to the calling app.
131
189
132
-
```cs
190
+
```csharp
133
191
ValueSetresult=newValueSet();
134
192
result["ReturnedData"] ="The returned result";
135
193
_operation.ReportCompleted(result);
136
194
```
137
195
196
+
```cppwinrt
197
+
ValueSet result;
198
+
result.Insert("ReturnedData", "The returned result");
199
+
_operation.ReportCompleted(result);
200
+
```
201
+
138
202
## Step 6: Write code to launch the app for results and get the returned data
139
203
140
204
141
205
Launch the app from within an async method in your calling app as shown in this example code. Note the **using** statements, which are necessary for the code to compile:
142
206
143
-
```cs
207
+
```csharp
144
208
usingSystem.Threading.Tasks;
145
209
usingWindows.System;
146
210
...
@@ -197,4 +261,4 @@ Then pass it to the launched app via **LaunchUriForResultsAsync**.
0 commit comments