Activity Startup
The
Activityclass 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 amainmethod, the Android system initiates code in anActivityinstance by invoking specific callback methods that correspond to specific stages of its lifecycle.
The UiAutomator2 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:
appium:appActivity: main application activity nameappium:appPackage: application package IDappium:appWaitActivity: application activity name to wait for/which starts the firstappium:appWaitPackage: application package ID to wait for/which starts the firstappium:appWaitDuration: maximum duration to wait untilappWaitActivityis focusedappium:appWaitForLaunch: whether to wait until Activity Manager returns the control to the calling process
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 UiAutomator2 Starts Activities¶
- Activities are started by Call Activity Manager
- UiAutomator2 tries to start the specified
appium:appPackage/appium:appActivitycombination - UiAutomator2 waits until the
appWaitPackage/appWaitActivityis focused (or theappWaitDurationtimeout expires) - The currently focused activity name is parsed from
adb shell dumpsys window windowscommand output (mFocusedAppormCurrentFocusentries)
For more details, check the implementation of the getFocusedPackageAndActivity method in the
appium-adb
package.
Troubleshooting¶
Refer to the Session Startup Issues guide for handling potential problems.