# AndroidBenchmarkRunner

Artifact: [androidx.benchmark:benchmark-junit4](https://developer.android.com/jetpack/androidx/releases/benchmark) [View Source](https://cs.android.com/search?q=file:androidx/benchmark/junit4/AndroidBenchmarkRunner.kt+class:androidx.benchmark.junit4.AndroidBenchmarkRunner) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

*** ** * ** ***


```
open class AndroidBenchmarkRunner : AndroidJUnitRunner
```

<br />

|---|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||||
| ↳ | [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) ||||
|   | ↳ | [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation) |||
|   |   | ↳ | [androidx.test.runner.AndroidJUnitRunner](https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner) ||
|   |   |   | ↳ | [androidx.benchmark.junit4.AndroidBenchmarkRunner](https://developer.android.com/reference/kotlin/androidx/benchmark/junit4/AndroidBenchmarkRunner) |

*** ** * ** ***

Instrumentation runner for benchmarks, used to increase stability of measurements and minimize interference.

To use this runner, put the following in your module level `build.gradle`:

```kotlin
android {
    defaultConfig {
        testInstrumentationRunner "androidx.benchmark.junit4.AndroidBenchmarkRunner"
    }
}
```

## Minimizing Interference

This runner launches a simple opaque activity used to reduce benchmark interference from other windows. Launching other activities is supported e.g. via ActivityTestRule and ActivityScenario - the opaque activity will be relaunched if not actively running before each test, and after each test's cleanup is complete.

For example, sources of potential interference:

- live wallpaper rendering

- homescreen widget updates

- hotword detection

- status bar repaints

- running in background (some cores may be foreground-app only)

## Clock Stability

While it is better for performance stability to lock clocks with the `./gradlew lockClocks` task provided by the gradle plugin, this is not possible on most devices. The runner provides a fallback mode for preventing thermal throttling.

On devices that support `https://developer.android.com/reference/android/view/Window.html#setSustainedPerformanceMode(boolean)`, the runner will set this mode on the window of every Activity launched (including the opaque Activity mentioned above). The runner will also launch a continuously spinning Thread. Together, these ensure that the app runs in the multithreaded stable performance mode, which locks the maximum clock frequency to prevent thermal throttling. This ensures stable clock levels across all benchmarks, even if a continuous suite of benchmarks runs for many minutes on end.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/benchmark/junit4/AndroidBenchmarkRunner#AndroidBenchmarkRunner()()` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/benchmark/junit4/AndroidBenchmarkRunner#onDestroy()()` |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/benchmark/junit4/AndroidBenchmarkRunner#waitForActivitiesToComplete()()` Ensures we've onStopped() all activities which were onStarted(). |

### Inherited functions

From [androidx.test.runner.AndroidJUnitRunner](https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner#onCreate(android.os.Bundle)(arguments: https://developer.android.com/reference/android/os/Bundle.html)`

Sets up lifecycle monitoring, and argument registry.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner#onException(java.lang.Object,java.lang.Throwable)(obj: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, e: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner#onStart()()`

This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/AndroidJUnitRunner#sendStatus(int,android.os.Bundle)(resultCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, results: https://developer.android.com/reference/android/os/Bundle.html)` From [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) `https://developer.android.com/reference/android/os/TestLooperManager.html` `https://developer.android.com/reference/android/app/Instrumentation.html#acquireLooperManager(android.os.Looper)(looper: https://developer.android.com/reference/android/os/Looper.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#addMonitor(android.app.Instrumentation.ActivityMonitor)(monitor: https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html` `https://developer.android.com/reference/android/app/Instrumentation.html#addMonitor(java.lang.String, android.app.Instrumentation.ActivityResult, boolean)(
cls: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
result: https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html,
block: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html` `https://developer.android.com/reference/android/app/Instrumentation.html#addMonitor(android.content.IntentFilter, android.app.Instrumentation.ActivityResult, boolean)(
filter: https://developer.android.com/reference/android/content/IntentFilter.html,
result: https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html,
block: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#addResults(android.os.Bundle)(results: https://developer.android.com/reference/android/os/Bundle.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnNewIntent(android.app.Activity, android.content.Intent)(activity: https://developer.android.com/reference/android/app/Activity.html, intent: https://developer.android.com/reference/android/content/Intent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnNewIntent(android.app.Activity, android.content.Intent, android.app.ComponentCaller)(
activity: https://developer.android.com/reference/android/app/Activity.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
caller: https://developer.android.com/reference/android/app/ComponentCaller.html
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPictureInPictureRequested(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPostCreate(android.app.Activity, android.os.Bundle)(activity: https://developer.android.com/reference/android/app/Activity.html, savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html?)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPostCreate(android.app.Activity, android.os.Bundle, android.os.PersistableBundle)(
activity: https://developer.android.com/reference/android/app/Activity.html,
savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html?,
persistentState: https://developer.android.com/reference/android/os/PersistableBundle.html?
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnRestoreInstanceState(android.app.Activity, android.os.Bundle)(
activity: https://developer.android.com/reference/android/app/Activity.html,
savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnRestoreInstanceState(android.app.Activity, android.os.Bundle, android.os.PersistableBundle)(
activity: https://developer.android.com/reference/android/app/Activity.html,
savedInstanceState: https://developer.android.com/reference/android/os/Bundle.html?,
persistentState: https://developer.android.com/reference/android/os/PersistableBundle.html?
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnSaveInstanceState(android.app.Activity, android.os.Bundle)(activity: https://developer.android.com/reference/android/app/Activity.html, outState: https://developer.android.com/reference/android/os/Bundle.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnSaveInstanceState(android.app.Activity, android.os.Bundle, android.os.PersistableBundle)(
activity: https://developer.android.com/reference/android/app/Activity.html,
outState: https://developer.android.com/reference/android/os/Bundle.html,
outPersistentState: https://developer.android.com/reference/android/os/PersistableBundle.html
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnUserLeaving(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#checkMonitorHit(android.app.Instrumentation.ActivityMonitor, int)(monitor: https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html, minHits: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#endPerformanceSnapshot()()` `https://developer.android.com/reference/android/app/UiAutomation.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation(int)(flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#invokeContextMenuAction(android.app.Activity, int, int)(targetActivity: https://developer.android.com/reference/android/app/Activity.html, id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, flag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#invokeMenuActionSync(android.app.Activity, int, int)(targetActivity: https://developer.android.com/reference/android/app/Activity.html, id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, flag: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#removeMonitor(android.app.Instrumentation.ActivityMonitor)(monitor: https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#resetInTouchMode()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendCharacterSync(int)(keyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeyDownUpSync(int)(keyCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendKeySync(android.view.KeyEvent)(event: https://developer.android.com/reference/android/view/KeyEvent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendPointerSync(android.view.MotionEvent)(event: https://developer.android.com/reference/android/view/MotionEvent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendStringSync(java.lang.String)(text: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#sendTrackballEventSync(android.view.MotionEvent)(event: https://developer.android.com/reference/android/view/MotionEvent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#setAutomaticPerformanceSnapshots()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#setInTouchMode(boolean)(inTouch: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#start()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#startActivitySync(android.content.Intent, android.os.Bundle)(intent: https://developer.android.com/reference/android/content/Intent.html, options: https://developer.android.com/reference/android/os/Bundle.html?)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#startAllocCounting()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#startPerformanceSnapshot()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#startProfiling()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#stopAllocCounting()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#stopProfiling()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdle(java.lang.Runnable)(recipient: https://developer.android.com/reference/java/lang/Runnable.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForIdleSync()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForMonitor(android.app.Instrumentation.ActivityMonitor)(monitor: https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html)` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/android/app/Instrumentation.html#waitForMonitorWithTimeout(android.app.Instrumentation.ActivityMonitor, long)(
monitor: https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html,
timeOut: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html
)` From [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnCreate(android.app.Activity,android.os.Bundle)(activity: https://developer.android.com/reference/android/app/Activity.html, bundle: https://developer.android.com/reference/android/os/Bundle.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnCreate(android.app.Activity,android.os.Bundle,android.os.PersistableBundle)(
activity: https://developer.android.com/reference/android/app/Activity.html,
bundle: https://developer.android.com/reference/android/os/Bundle.html,
persistentState: https://developer.android.com/reference/android/os/PersistableBundle.html
)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnDestroy(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnPause(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnRestart(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnResume(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnStart(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callActivityOnStop(android.app.Activity)(activity: https://developer.android.com/reference/android/app/Activity.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#callApplicationOnCreate(android.app.Application)(app: https://developer.android.com/reference/android/app/Application.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#dumpThreadStateToOutputs(java.lang.String)(outputFileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivities(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent[],android.os.Bundle)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://developer.android.com/reference/android/app/Activity.html,
intents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/android/content/Intent.html>,
options: https://developer.android.com/reference/android/os/Bundle.html
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://developer.android.com/reference/android/app/Activity.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int,android.os.Bundle)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://developer.android.com/reference/android/app/Activity.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,
options: https://developer.android.com/reference/android/os/Bundle.html
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Fragment,android.content.Intent,int,android.os.Bundle)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://developer.android.com/reference/android/app/Fragment.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,
options: https://developer.android.com/reference/android/os/Bundle.html
)` `https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,java.lang.String,android.content.Intent,int,android.os.Bundle)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,
options: https://developer.android.com/reference/android/os/Bundle.html
)`

This API was added in Android API 23 (M)
`https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#execStartActivity(android.content.Context,android.os.IBinder,android.os.IBinder,android.app.Activity,android.content.Intent,int,android.os.Bundle,android.os.UserHandle)(
who: https://developer.android.com/reference/android/content/Context.html,
contextThread: https://developer.android.com/reference/android/os/IBinder.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
target: https://developer.android.com/reference/android/app/Activity.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
requestCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html,
options: https://developer.android.com/reference/android/os/Bundle.html,
user: https://developer.android.com/reference/android/os/UserHandle.html
)`

This API was added in Android API 17 (JELLY_BEAN_MR1)
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#finish(int,android.os.Bundle)(resultCode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, results: https://developer.android.com/reference/android/os/Bundle.html)`

Ensures all activities launched in this instrumentation are finished before the instrumentation exits.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[installMultidex](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#installMultidex())()`

**This function is deprecated.**

no-op: multidex is not necessary on SDKS \>= 23

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[installOldMultiDex](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#installOldMultiDex(java.lang.Class<?>))(multidexClass: https://developer.android.com/reference/java/lang/Class.html<*>)`

**This function is deprecated.**

no-op: multidex is not necessary on SDKS \>= 23

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#interceptActivityUsing(androidx.test.runner.intercepting.InterceptingActivityFactory)(
interceptingActivityFactory: https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/InterceptingActivityFactory
)`

Use the given InterceptingActivityFactory to create Activity instance in `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)`.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `[isPrimaryInstrProcess](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess(java.lang.String))(argsProcessName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?)`

**This function is deprecated.**

use isPrimaryInstrProcess()

<br />

`https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)(cl: https://developer.android.com/reference/java/lang/ClassLoader.html, className: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, intent: https://developer.android.com/reference/android/content/Intent.html)` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.Class<?>,android.content.Context,android.os.IBinder,android.app.Application,android.content.Intent,android.content.pm.ActivityInfo,java.lang.CharSequence,android.app.Activity,java.lang.String,java.lang.Object)(
clazz: https://developer.android.com/reference/java/lang/Class.html<*>,
context: https://developer.android.com/reference/android/content/Context.html,
token: https://developer.android.com/reference/android/os/IBinder.html,
application: https://developer.android.com/reference/android/app/Application.html,
intent: https://developer.android.com/reference/android/content/Intent.html,
info: https://developer.android.com/reference/android/content/pm/ActivityInfo.html,
title: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html,
parent: https://developer.android.com/reference/android/app/Activity.html,
id: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html,
lastNonConfigurationInstance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html
)` `https://developer.android.com/reference/android/app/Application.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#newApplication(java.lang.ClassLoader,java.lang.String,android.content.Context)(cl: https://developer.android.com/reference/java/lang/ClassLoader.html, className: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, context: https://developer.android.com/reference/android/content/Context.html)`

Does initialization before creating the application.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#restoreUncaughtExceptionHandler()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#runOnMainSync(java.lang.Runnable)(runnable: https://developer.android.com/reference/java/lang/Runnable.html)`

Posts a runnable to the main thread and blocks the caller's thread until the runnable is executed.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#setJsBridgeClassName(java.lang.String)(className: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#shouldWaitForActivitiesToComplete()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#specifyDexMakerCacheProperty()()` `https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#startActivitySync(android.content.Intent)(intent: https://developer.android.com/reference/android/content/Intent.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#unwrapException(java.lang.Throwable)(t: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html)`

Unwraps an exception from certain wrapper types, e.g. RuntimeException.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#useDefaultInterceptingActivityFactory()()`

Use default mechanism of creating activity instance in `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)`

### Inherited properties

From [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) `open https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#allocCounts` `open https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#binderCounts` `open https://developer.android.com/reference/android/content/ComponentName.html` `https://developer.android.com/reference/android/app/Instrumentation.html#componentName` `open https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#context` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#isProfiling` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/android/app/Instrumentation.html#processName` `open https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#targetContext` `open https://developer.android.com/reference/android/app/UiAutomation.html` `https://developer.android.com/reference/android/app/Instrumentation.html#uiAutomation` From [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess()` `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` `https://developer.android.com/reference/kotlin/androidx/test/runner/MonitoringInstrumentation#threadState()`

## Public constructors

### AndroidBenchmarkRunner

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/benchmark#1.0.0)

```
AndroidBenchmarkRunner()
```

## Public functions

### onDestroy

```
@CallSuper
open fun onDestroy(): Unit
```

## Protected functions

### waitForActivitiesToComplete

```
@CallSuper
protected open fun waitForActivitiesToComplete(): Unit
```

Ensures we've onStopped() all activities which were onStarted().

According to Activity's contract, the process is not killable between onStart and onStop. Breaking this contract (which finish() will if you let it) can cause bad behaviour (including a full restart of system_server).

We give the app 2 seconds to stop all its activities, then we proceed.

This should never be run on the main thread.