Passing Arguments to an App or Game

Arguments can be passed to a title at launch time as either addtional parameters to the xbapp launch command or as part of the URI used in protocol activation.

Specifying Launch Arguments with xbapp launch

Launch arguments are specified in the xbapp launch command by appending values to the end of the command.

xbapp launch app_user_model_ID {parameter1 parameter2 parameter3 ...}  

Specifying Launch Arguments in Visual Studio

Properties can be specified in a project’s properties page in Command Arguments under the Debugging section. See Visual Studio Properties for Xbox One Development for more information on the debugging properties.

Specifying Launch Arguments with Protocol Activation

Launch arguments are specified in protocol activation by appending argument value pairs to the end of the URI used to activate the title:

ms-xbl-TitleID://authority?arg1=value1&arg2=value2...  

Protocol activation can be tested using xbapp launch and specifying the protocol activation URI:

xbapp launch URI  

See Deep Linking in Xbox One for additional information on protocol activation.

Note The title ID for a title is specified in the mx:XboxLive element in the title’s Package.appxmanifest file. See Setting Up Sandboxes for Xbox Live Development for more information.

Accessing Launch Arguments

Launch arguments are passed to the game through the Arguments property on the LaunchActivatedEventArgs class. An instance of LaunchActivatedEventArgs is sent to the game as a parameter to the Activated event on CoreApplicationView. The Activated event receives event arguments of type IActivatedEventArgs, which has Kind, a property. If IActivatedEventArgs::Kind is Launch, then you can use QueryInterface for the ILaunchActivatedEventArgs interface, and use the Arguments property of that interface.

The following code is an example of how a game would access parameters passed in through xbapp launch or as part of an activation URL.

void ApplicationView::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^ args) 
{ 
  if (args->Kind == ActivationKind::Launch) 
  { 
    LaunchActivatedEventArgs ^launchArgs = (LaunchActivatedEventArgs ^) args; 
    Platform::String ^commandlineParams = launchArgs->Arguments; 
    /* parse commandlineParams .... */ 
  } 
  else if (args->Kind == ActivationKind::Protocol)
  {
    ProtocolActivatedEventArgs ^ proArgs = (ProtocolActivatedEventArgs ^) args;
    Platform::String ^ rawUri = proArgs->Uri->RawUri;
    /* parse URI ... */
  }
    
  ActivationKind activationKind = args->Kind;
  ApplicationExecutionState previousExecutionState = args->PreviousExecutionState;  
    
  CoreWindow::GetForCurrentThread()->Activate(); 
}  

Note For development only purposes, the GetLaunchActivationArgs method can be used to retrieve launch arguments before the Activated event is fired.

See also

Deep Linking in Xbox One

Visual Studio Properties for Xbox One Development