# MonitoringInstrumentation

Artifact: [androidx.test:monitor](https://developer.android.com/jetpack/androidx/releases/test) [View Source](https://cs.android.com/search?q=file:androidx/test/runner/MonitoringInstrumentation.java+class:androidx.test.runner.MonitoringInstrumentation)

*** ** * ** ***


```
public class MonitoringInstrumentation extends Instrumentation
```

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

Known direct subclasses [AndroidJUnitRunner](https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner)

|---|---|
| `https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner` | An `https://developer.android.com/reference/android/app/Instrumentation.html` that runs JUnit3 and JUnit4 tests against an Android package (application). |

Known indirect subclasses [AndroidBenchmarkRunner](https://developer.android.com/reference/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. |

*** ** * ** ***

An instrumentation that enables several advanced features and makes some hard guarantees about the state of the application under instrumentation.

A short list of these capabilities:

- Forces Application.onCreate() to happen before Instrumentation.onStart() runs (ensuring your code always runs in a sane state).
- Logs application death due to exceptions.
- Allows tracking of activity lifecycle states.
- Registers instrumentation arguments in an easy to access place.
- Ensures your activities are creating themselves in reasonable amounts of time.
- Provides facilities to dump current app threads to test outputs.
- Ensures all activities finish before instrumentation exits.

This Instrumentation is \*NOT\* a test instrumentation (some of its subclasses are). It makes no assumptions about what the subclass wants to do.

## Summary

| ### Nested types |
|---|
| `public inner class https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation.ActivityFinisher implements https://developer.android.com/reference/java/lang/Runnable.html` Loops through all the activities that have not yet finished and explicitly calls finish on them. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#MonitoringInstrumentation()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnCreate(android.app.Activity,android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, 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/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html bundle, 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/android/app/Activity.html activity)` |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnPause(android.app.Activity)(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/android/app/Activity.html activity)` |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnResume(android.app.Activity)(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/android/app/Activity.html activity)` |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#callActivityOnStop(android.app.Activity)(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/android/app/Application.html app)` |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Activity.html target, Intent[] intents, https://developer.android.com/reference/android/os/Bundle.html options )` |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Activity.html target, https://developer.android.com/reference/android/content/Intent.html intent, int requestCode )` |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Activity.html target, https://developer.android.com/reference/android/content/Intent.html intent, int requestCode, https://developer.android.com/reference/android/os/Bundle.html options )` |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Fragment.html target, https://developer.android.com/reference/android/content/Intent.html intent, int requestCode, https://developer.android.com/reference/android/os/Bundle.html options )` |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/java/lang/String.html target, https://developer.android.com/reference/android/content/Intent.html intent, int requestCode, https://developer.android.com/reference/android/os/Bundle.html options )` This API was added in Android API 23 (M) |
| `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/android/content/Context.html who, https://developer.android.com/reference/android/os/IBinder.html contextThread, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Activity.html target, https://developer.android.com/reference/android/content/Intent.html intent, int requestCode, https://developer.android.com/reference/android/os/Bundle.html options, 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/android/os/Bundle.html results)` Ensures all activities launched in this instrumentation are finished before the instrumentation exits. |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#interceptActivityUsing(androidx.test.runner.intercepting.InterceptingActivityFactory)( 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)`. |
| `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/java/lang/ClassLoader.html cl, https://developer.android.com/reference/java/lang/String.html className, https://developer.android.com/reference/android/content/Intent.html intent)` |
| `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/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/android/os/IBinder.html token, https://developer.android.com/reference/android/app/Application.html application, https://developer.android.com/reference/android/content/Intent.html intent, https://developer.android.com/reference/android/content/pm/ActivityInfo.html info, https://developer.android.com/reference/java/lang/CharSequence.html title, https://developer.android.com/reference/android/app/Activity.html parent, https://developer.android.com/reference/java/lang/String.html id, https://developer.android.com/reference/java/lang/Object.html lastNonConfigurationInstance )` |
| `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/java/lang/ClassLoader.html cl, https://developer.android.com/reference/java/lang/String.html className, 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#onCreate(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html arguments)` Sets up lifecycle monitoring, and argument registry. |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#onDestroy()()` |
| `boolean` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#onException(java.lang.Object,java.lang.Throwable)(https://developer.android.com/reference/java/lang/Object.html obj, https://developer.android.com/reference/java/lang/Throwable.html e)` |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#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/MonitoringInstrumentation#runOnMainSync(java.lang.Runnable)(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. |
| `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/android/content/Intent.html intent)` |
| `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)` |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#dumpThreadStateToOutputs(java.lang.String)(https://developer.android.com/reference/java/lang/String.html outputFileName)` |
| `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/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 /> |
| `final boolean` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess()()` Checks whether this instance of instrumentation should be considered as a primary instrumentation process. |
| `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 /> |
| `void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#restoreUncaughtExceptionHandler()()` |
| `final void` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#setJsBridgeClassName(java.lang.String)(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/java/lang/Throwable.html` | `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#unwrapException(java.lang.Throwable)(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#waitForActivitiesToComplete()()` Ensures we've onStopped() all activities which were onStarted(). |

### Inherited Constants

From [android.app.Instrumentation](https://developer.android.com/reference/android/app/Instrumentation.html) `static final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#REPORT_KEY_IDENTIFIER = "id"` `static final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#REPORT_KEY_STREAMRESULT = "stream"`

### Inherited methods

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)(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/android/app/Instrumentation.ActivityMonitor.html monitor)` `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/android/content/IntentFilter.html filter,
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/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/android/app/Activity.html activity, https://developer.android.com/reference/android/content/Intent.html intent)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnPictureInPictureRequested(android.app.Activity)(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/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#callActivityOnRestoreInstanceState(android.app.Activity, android.os.Bundle)(
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#callActivityOnSaveInstanceState(android.app.Activity, android.os.Bundle)(https://developer.android.com/reference/android/app/Activity.html activity, https://developer.android.com/reference/android/os/Bundle.html outState)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#callActivityOnUserLeaving(android.app.Activity)(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/android/app/Instrumentation.ActivityMonitor.html monitor, int minHits)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#endPerformanceSnapshot()()` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getAllocCounts()()` `https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getBinderCounts()()` `https://developer.android.com/reference/android/content/ComponentName.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getComponentName()()` `https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getContext()()` `https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getProcessName()()` `https://developer.android.com/reference/android/content/Context.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getTargetContext()()` `https://developer.android.com/reference/android/app/UiAutomation.html` `https://developer.android.com/reference/android/app/Instrumentation.html#getUiAutomation()()` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#invokeContextMenuAction(android.app.Activity, int, int)(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/android/app/Activity.html targetActivity, int id, int flag)` `boolean` `https://developer.android.com/reference/android/app/Instrumentation.html#isProfiling()()` `static https://developer.android.com/reference/android/app/Application.html` `https://developer.android.com/reference/android/app/Instrumentation.html#newApplication(java.lang.Class&lt;?&gt;, android.content.Context)(https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> clazz, https://developer.android.com/reference/android/content/Context.html context)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#removeMonitor(android.app.Instrumentation.ActivityMonitor)(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/android/view/KeyEvent.html event)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendPointerSync(android.view.MotionEvent)(https://developer.android.com/reference/android/view/MotionEvent.html event)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendStatus(int, android.os.Bundle)(int resultCode, https://developer.android.com/reference/android/os/Bundle.html results)` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#sendStringSync(java.lang.String)(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/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()()` `void` `https://developer.android.com/reference/android/app/Instrumentation.html#startAllocCounting()()`

**This method is deprecated.**
`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()()`

**This method is deprecated.**
`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/java/lang/Runnable.html recipient)` `void` `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)(https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor.html monitor)` `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/android/app/Instrumentation.ActivityMonitor.html monitor,
long timeOut
)`

## Public constructors

### MonitoringInstrumentation

```
public MonitoringInstrumentation()
```

## Public methods

### callActivityOnCreate

```
public void callActivityOnCreate(Activity activity, Bundle bundle)
```

### callActivityOnCreate

```
public void callActivityOnCreate(
    Activity activity,
    Bundle bundle,
    PersistableBundle persistentState
)
```

### callActivityOnDestroy

```
public void callActivityOnDestroy(Activity activity)
```

### callActivityOnPause

```
public void callActivityOnPause(Activity activity)
```

### callActivityOnRestart

```
public void callActivityOnRestart(Activity activity)
```

### callActivityOnResume

```
public void callActivityOnResume(Activity activity)
```

### callActivityOnStart

```
public void callActivityOnStart(Activity activity)
```

### callActivityOnStop

```
public void callActivityOnStop(Activity activity)
```

### callApplicationOnCreate

```
public void callApplicationOnCreate(Application app)
```

### execStartActivities

```
public void execStartActivities(
    Context who,
    IBinder contextThread,
    IBinder token,
    Activity target,
    Intent[] intents,
    Bundle options
)
```

### execStartActivity

```
public Instrumentation.ActivityResult execStartActivity(
    Context who,
    IBinder contextThread,
    IBinder token,
    Activity target,
    Intent intent,
    int requestCode
)
```

### execStartActivity

```
public Instrumentation.ActivityResult execStartActivity(
    Context who,
    IBinder contextThread,
    IBinder token,
    Activity target,
    Intent intent,
    int requestCode,
    Bundle options
)
```

### execStartActivity

```
public Instrumentation.ActivityResult execStartActivity(
    Context who,
    IBinder contextThread,
    IBinder token,
    Fragment target,
    Intent intent,
    int requestCode,
    Bundle options
)
```

### execStartActivity

```
public Instrumentation.ActivityResult execStartActivity(
    Context who,
    IBinder contextThread,
    IBinder token,
    String target,
    Intent intent,
    int requestCode,
    Bundle options
)
```

This API was added in Android API 23 (M)

### execStartActivity

```
public Instrumentation.ActivityResult execStartActivity(
    Context who,
    IBinder contextThread,
    IBinder token,
    Activity target,
    Intent intent,
    int requestCode,
    Bundle options,
    UserHandle user
)
```

This API was added in Android API 17 (JELLY_BEAN_MR1)

### finish

```
public void finish(int resultCode, Bundle results)
```

Ensures all activities launched in this instrumentation are finished before the instrumentation exits.

Subclasses who override this method should do their finish processing and then call super.finish to invoke this logic. Not waiting for all activities to finish() before exiting can cause device wide instability.

### interceptActivityUsing

```
public void interceptActivityUsing(
    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)`. This can be used to override default behavior of activity in tests e.g. mocking startService() method in Activity under test, to avoid starting the real service and instead verifying that a particular service was started.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/test/runner/intercepting/InterceptingActivityFactory interceptingActivityFactory` | InterceptingActivityFactory to be used for creating activity instance in `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newActivity(java.lang.ClassLoader,java.lang.String,android.content.Intent)` |

### newActivity

```
public Activity newActivity(ClassLoader cl, String className, Intent intent)
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InstantiationException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException.html` |   |

### newActivity

```
public Activity newActivity(
    Class<@NonNull ?> clazz,
    Context context,
    IBinder token,
    Application application,
    Intent intent,
    ActivityInfo info,
    CharSequence title,
    Activity parent,
    String id,
    Object lastNonConfigurationInstance
)
```

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InstantiationException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |

### newApplication

```
public Application newApplication(ClassLoader cl, String className, Context context)
```

Does initialization before creating the application.

Note, `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#newApplication(java.lang.ClassLoader,java.lang.String,android.content.Context)` is called before `https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#onCreate(android.os.Bundle)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/InstantiationException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |
| `https://developer.android.com/reference/java/lang/ClassNotFoundException.html` |   |

### onCreate

```
public void onCreate(Bundle arguments)
```

Sets up lifecycle monitoring, and argument registry.

Subclasses must call up to onCreate(). This onCreate method does not call start() it is the subclasses responsibility to call start if it desires.

### onDestroy

```
public void onDestroy()
```

### onException

```
public boolean onException(Object obj, Throwable e)
```

### onStart

```
public void onStart()
```

This implementation of onStart() will guarantee that the Application's onCreate method has completed when it returns.

Subclasses should call super.onStart() before executing any code that touches the application and it's state.

### runOnMainSync

```
public void runOnMainSync(Runnable runnable)
```

Posts a runnable to the main thread and blocks the caller's thread until the runnable is executed. When a Throwable is thrown in the runnable, the exception is propagated back to the caller's thread. If it is an unchecked throwable, it will be rethrown as is. If it is a checked exception, it will be rethrown as a `https://developer.android.com/reference/java/lang/RuntimeException.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/Runnable.html runnable` | a runnable to be executed on the main thread |

### startActivitySync

```
public Activity startActivitySync(Intent intent)
```

### useDefaultInterceptingActivityFactory

```
public void 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)`

## Protected methods

### dumpThreadStateToOutputs

```
protected void dumpThreadStateToOutputs(String outputFileName)
```

### getThreadState

```
protected String getThreadState()
```

### installMultidex

```
protected void [installMultidex](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#installMultidex())()
```

> [!CAUTION]
> **This method is deprecated.**   
>
> no-op: multidex is not necessary on SDKS \>= 23

### installOldMultiDex

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

> [!CAUTION]
> **This method is deprecated.**   
>
> no-op: multidex is not necessary on SDKS \>= 23

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NoSuchMethodException.html` |   |
| `https://developer.android.com/reference/java/lang/reflect/InvocationTargetException.html` |   |
| `https://developer.android.com/reference/java/lang/IllegalAccessException.html` |   |

### isPrimaryInstrProcess

```
protected final boolean isPrimaryInstrProcess()
```

Checks whether this instance of instrumentation should be considered as a primary instrumentation process.

Prior to API 26, instrumentation could only run in a single process and that would be the primary process. Post API 26, the primary process is the first process listed in android:targetProcesses or the default process of the targetPackage.

| Returns |
|---|---|
| `boolean` | `true` if the given process is the primary instrumentation process |

### isPrimaryInstrProcess

```
protected boolean [isPrimaryInstrProcess](https://developer.android.com/reference/androidx/test/runner/MonitoringInstrumentation#isPrimaryInstrProcess(java.lang.String))(@Nullable String argsProcessName)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use isPrimaryInstrProcess()

Checks whether this instance of instrumentation should be considered as a primary instrumentation process.

Prior to API 26, instrumentation could only run in a single process and that would be the primary process. Post API 26, the primary process is the first process listed in android:targetProcesses or the default process of the targetPackage.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html argsProcessName` | unused. |

| Returns |
|---|---|
| `boolean` | `true` if the given process is the primary instrumentation process |

### restoreUncaughtExceptionHandler

```
protected void restoreUncaughtExceptionHandler()
```

### setJsBridgeClassName

```
protected final void setJsBridgeClassName(String className)
```

### shouldWaitForActivitiesToComplete

```
protected boolean shouldWaitForActivitiesToComplete()
```

### specifyDexMakerCacheProperty

```
protected void specifyDexMakerCacheProperty()
```

### unwrapException

```
protected Throwable unwrapException(Throwable t)
```

Unwraps an exception from certain wrapper types, e.g. RuntimeException.

We consider two exceptions the same if they are caused by the same root cause. For example, when an exception occurs on the main thread, the #onException method is first called to handle it, and the exception is wrapped with RuntimeException and re-thrown, which is then caught by the uncaught exception handler. In this case, the exception should only be handled once.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable.html` | the root cause of the given exception |

### waitForActivitiesToComplete

```
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.