---
name: Background App
short_description: Send the currently running app for this session to the background
description:
  >
    Send the currently active app to the background, and either return after a
    certain amount of time, or leave the app deactivated.

    There are 3 types of parameters which may be passed to this method:


    1. An object that looks like `{"timeout": secs}`, where `secs` is an
       integer designating how long, in seconds, to background the app for. -1
       means to deactivate the app entirely.

    2. `null`, which means to deactivate the app entirely.

    3. _Deprecated_ An integer: how long, in seconds, to background the app for. -1 means to
       deactivate the app entirely.


    iOS tests with XCUITest can also use the `mobile: terminateApp` method to
    terminate the current app (see detailed [documentation](/docs/en/writing-running-appium/ios/ios-xctest-mobile-apps-management.md#mobile-terminateapp)),
    and the `mobile: activateApp` to activate an existing application on the
    device under test and moves it to the foreground (see detailed [documentation](/docs/en/writing-running-appium/ios/ios-xctest-mobile-apps-management.md#mobile-activateapp)).
example_usage:
  java:
    |
      driver.runAppInBackground(Duration.ofSeconds(10));
  python:
    |
      self.driver.background_app(10)
  javascript_wd:
    |
      await driver.backgroundApp(10);
  javascript_wdio:
    |
      driver.background(10);
  ruby:
    |
      @driver.background_app(10)
  php:
    |
      $driver->backgroundApp(10);
  csharp:
    |
      // TODO C# sample

client_docs:
  java: "http://appium.github.io/java-client/io/appium/java_client/InteractsWithApps.html#runAppInBackground-java.time.Duration-"
  python: "https://github.com/appium/python-client/blob/master/appium/webdriver/webdriver.py#L529"
  javascript_wdio: "http://webdriver.io/api/mobile/background.html"
  javascript_wd: "https://github.com/admc/wd/blob/master/lib/commands.js#L2841"
  ruby: "http://www.rubydoc.info/github/appium/ruby_lib_core/Appium/Core/Device#background_app-instance_method"
  php: "https://github.com/appium/php-client/" # TODO PHP documentation link
  csharp: "https://github.com/appium/appium-dotnet-driver/" # TODO Dotnet documentation link

# Driver support by platform
driver_support:
  ios:
    xcuitest: true
    uiautomation: true
  android:
    uiautomator2: true
    uiautomator: true
  mac:
    mac: false
  windows:
    windows: false
client_support:
  java: true
  python: true
  ruby: true
  php: true
  csharp: true
  javascript_wd: true
  javascript_wdio: true


# Information about the HTTP endpoints
endpoint:
  url: /session/:session_id/appium/app/background
  method: 'POST'
  url_parameters:
    - name: session_id
      description: ID of the session to route the command to
  json_parameters:
    - name: seconds
      type: number
      description: How long to run app in background.

# Links to specifications. Should link to at least one specification
specifications:
  jsonwp: https://github.com/appium/appium-base-driver/blob/master/lib/mjsonwp/routes.js#L439
