# 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)

*** ** * ** ***


```
public class AndroidBenchmarkRunner extends AndroidJUnitRunner
```

<br />

|---|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||||
| ↳ | [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) ||||
|   | ↳ | [androidx.test.runner.MonitoringInstrumentation](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation) |||
|   |   | ↳ | [androidx.test.runner.AndroidJUnitRunner](https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner) ||
|   |   |   | ↳ | [androidx.benchmark.junit4.AndroidBenchmarkRunner](https://developer.android.com/reference/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`:

```
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/androidx/benchmark/junit4/AndroidBenchmarkRunner#AndroidBenchmarkRunner()()` |

| ### Public methods |
|---|---|
| `void` | `@https://developer.android.com/reference/androidx/annotation/CallSuper https://developer.android.com/reference/androidx/benchmark/junit4/AndroidBenchmarkRunner#onDestroy()()` |

| ### Protected methods |
|---|---|
| `void` | `@https://developer.android.com/reference/androidx/annotation/CallSuper https://developer.android.com/reference/androidx/benchmark/junit4/AndroidBenchmarkRunner#waitForActivitiesToComplete()()` Ensures we've onStopped() all activities which were onStarted(). |

### Inherited methods

From [androidx.test.runner.AndroidJUnitRunner](https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner) `void` `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onCreate(android.os.Bundle)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html arguments)`

Sets up lifecycle monitoring, and argument registry.
`boolean` `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onException(java.lang.Object,java.lang.Throwable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html obj, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html e)` `void` `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner#onStart()()`

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

This API was added in Android API 23 (M)
`@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html` `https://developer.android.com/reference/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)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html who,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/IBinder.html contextThread,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/IBinder.html token,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html target,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent,
int requestCode,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html options,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/UserHandle.html user
)`

This API was added in Android API 17 (JELLY_BEAN_MR1)
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#finish(int,android.os.Bundle)(int resultCode, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html results)`

Ensures all activities launched in this instrumentation are finished before the instrumentation exits.
`@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#getThreadState()()` `void` `[installMultidex](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#installMultidex())()`

**This method is deprecated.**

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

<br />

`void` `[installOldMultiDex](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#installOldMultiDex(java.lang.Class<?>))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> multidexClass)`

**This method is deprecated.**

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

<br />

`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#interceptActivityUsing(androidx.test.runner.intercepting.InterceptingActivityFactory)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/runner/intercepting/InterceptingActivityFactory interceptingActivityFactory
)`

Use the given InterceptingActivityFactory to create Activity instance in `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)`.
`final boolean` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess()()` `boolean` `[isPrimaryInstrProcess](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess(java.lang.String))(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html argsProcessName)`

**This method is deprecated.**

use isPrimaryInstrProcess()

<br />

`@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/ClassLoader.html cl,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html className,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent
)` `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/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)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/IBinder.html token,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Application.html application,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/pm/ActivityInfo.html info,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html title,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html parent,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html id,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html lastNonConfigurationInstance
)` `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Application.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newApplication(java.lang.ClassLoader,java.lang.String,android.content.Context)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/ClassLoader.html cl,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html className,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context
)`

Does initialization before creating the application.
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#restoreUncaughtExceptionHandler()()` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#runOnMainSync(java.lang.Runnable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Runnable.html runnable)`

Posts a runnable to the main thread and blocks the caller's thread until the runnable is executed.
`final void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#setJsBridgeClassName(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html className)` `boolean` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#shouldWaitForActivitiesToComplete()()` `void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#specifyDexMakerCacheProperty()()` `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/app/Activity.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#startActivitySync(android.content.Intent)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Intent.html intent)` `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#unwrapException(java.lang.Throwable)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Throwable.html t)`

Unwraps an exception from certain wrapper types, e.g. RuntimeException.
`void` `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#useDefaultInterceptingActivityFactory()()`

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

## Public constructors

### AndroidBenchmarkRunner

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

```
public AndroidBenchmarkRunner()
```

## Public methods

### onDestroy

```
@CallSuper
public void onDestroy()
```

## Protected methods

### waitForActivitiesToComplete

```
@CallSuper
protected void waitForActivitiesToComplete()
```

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.