Skip to content

Activity Startup

The Activity class is a crucial component of an Android app, and the way activities are launched and put together is a fundamental part of the platform's application model. Unlike programming paradigms in which apps are launched with a main method, the Android system initiates code in an Activity instance by invoking specific callback methods that correspond to specific stages of its lifecycle.

© Android Developer Documentation

The Espresso driver needs to know package and activity names in order to properly initialize the application under test. This information is expected to be provided in session capabilities.

Startup Capabilities

The driver supports multiple activity startup-related capabilities:

All of these capabilities are optional. If they are not set explicitly, the driver tries to auto-detect them by reading their values from the manifest of the APK file specified using the appium:app capability.

If the application under test is supposed to be already installed on the device, then at least the appium:appActivity and appium:appPackage capabilities must be set, since no package manifest is available in such case.

For more details, check the implementation of the packageAndLaunchActivityFromManifest method in the appium-adb package.

How Espresso Starts Activities

  1. Activities are started by Android Instrumentation
  2. Espresso tries to start the specified appium:appPackage/appium:appActivity combination
  3. Espresso waits until the appWaitPackage/appWaitActivity is focused (or the appWaitDuration timeout expires)
  4. The currently focused activity name is parsed from adb shell dumpsys window windows command output (mFocusedApp or mCurrentFocus entries)

For more details, check the implementation of the getFocusedPackageAndActivity method in the appium-adb package, as well as the startActivity helper inside the Espresso server code.

Troubleshooting

Refer to the Session Startup Issues guide for handling potential issues.