# Instrumentation

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/app/Instrumentation#nestedclasses)\|[Constants](https://developer.android.com/reference/android/app/Instrumentation#constants)\|[Ctors](https://developer.android.com/reference/android/app/Instrumentation#pubctors)\|[Methods](https://developer.android.com/reference/android/app/Instrumentation#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/Instrumentation#inhmethods)  

# Instrumentation

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/Instrumentation "View this page in Kotlin")\|Java

`
public


class
Instrumentation
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.Instrumentation |

|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [InstrumentationTestRunner](https://developer.android.com/reference/android/test/InstrumentationTestRunner),[LaunchPerformanceBase](https://developer.android.com/reference/android/test/LaunchPerformanceBase) |-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [InstrumentationTestRunner](https://developer.android.com/reference/android/test/InstrumentationTestRunner) | *This class was deprecated in API level 24. Use[AndroidJUnitRunner](https://developer.android.com/reference/android/support/test/runner/AndroidJUnitRunner)instead. New tests should be written using the[Android Testing Support Library](https://developer.android.com/tools/testing-support-library).* | | [LaunchPerformanceBase](https://developer.android.com/reference/android/test/LaunchPerformanceBase)         | Base class for all launch performance Instrumentation classes.                                                                                                                                                                                                                                            | |

<br />

*** ** * ** ***

Base class for implementing application instrumentation code. When running with instrumentation turned on, this class will be instantiated for you before any of the application code, allowing you to monitor all of the interaction the system has with the application. An Instrumentation implementation is described to the system through an AndroidManifest.xml's \<instrumentation\> tag.

## Summary

|                                                                                              ### Nested classes                                                                                               ||
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor) Information about a particular kind of Intent that is being monitored.       |
| ` class` | [Instrumentation.ActivityResult](https://developer.android.com/reference/android/app/Instrumentation.ActivityResult) Description of a Activity execution result to return to the original activity. |

|                                                                                                                                                                      ### Constants                                                                                                                                                                      ||
|--------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | [REPORT_KEY_IDENTIFIER](https://developer.android.com/reference/android/app/Instrumentation#REPORT_KEY_IDENTIFIER) If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the class that is writing the report.                          |
| [String](https://developer.android.com/reference/java/lang/String) | [REPORT_KEY_STREAMRESULT](https://developer.android.com/reference/android/app/Instrumentation#REPORT_KEY_STREAMRESULT) If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies a string which can simply be printed to the output stream. |

|                                               ### Public constructors                                               ||
|------------------------------------------------------------------------------------------------------------------|---|
| ` `[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation#Instrumentation())`() ` |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ||
|---------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[TestLooperManager](https://developer.android.com/reference/android/os/TestLooperManager)                              | ` `[acquireLooperManager](https://developer.android.com/reference/android/app/Instrumentation#acquireLooperManager(android.os.Looper))`(`[Looper](https://developer.android.com/reference/android/os/Looper)` looper) ` Takes control of the execution of messages on the specified looper until[TestLooperManager.release](https://developer.android.com/reference/android/os/TestLooperManager#release())is called.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` `[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor) | ` `[addMonitor](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(java.lang.String,%20android.app.Instrumentation.ActivityResult,%20boolean))`(`[String](https://developer.android.com/reference/java/lang/String)` cls, `[Instrumentation.ActivityResult](https://developer.android.com/reference/android/app/Instrumentation.ActivityResult)` result, boolean block) ` A convenience wrapper for[addMonitor(android.app.Instrumentation.ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))that creates a class matching[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)for you and returns it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` `[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor) | ` `[addMonitor](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.content.IntentFilter,%20android.app.Instrumentation.ActivityResult,%20boolean))`(`[IntentFilter](https://developer.android.com/reference/android/content/IntentFilter)` filter, `[Instrumentation.ActivityResult](https://developer.android.com/reference/android/app/Instrumentation.ActivityResult)` result, boolean block) ` A convenience wrapper for[addMonitor(android.app.Instrumentation.ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))that creates an intent filter matching[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)for you and returns it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` void`                                                                                                                   | ` `[addMonitor](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))`(`[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)` monitor) ` Add a new[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)that will be checked whenever an activity is started.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                   | ` `[addResults](https://developer.android.com/reference/android/app/Instrumentation#addResults(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` Report some results in the middle of instrumentation execution.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` void`                                                                                                                   | ` `[callActivityOnCreate](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnCreate(android.app.Activity,%20android.os.Bundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` icicle) ` Perform calling of an activity's[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` void`                                                                                                                   | ` `[callActivityOnCreate](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnCreate(android.app.Activity,%20android.os.Bundle,%20android.os.PersistableBundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` icicle, `[PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle)` persistentState) ` Perform calling of an activity's[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                   | ` `[callActivityOnDestroy](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnDestroy(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` void`                                                                                                                   | ` `[callActivityOnNewIntent](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnNewIntent(android.app.Activity,%20android.content.Intent,%20android.app.ComponentCaller))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Intent](https://developer.android.com/reference/android/content/Intent)` intent, `[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)` caller) ` Same as[callActivityOnNewIntent(android.app.Activity, android.content.Intent)](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnNewIntent(android.app.Activity,%20android.content.Intent)), but with an extra parameter for the[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instance associated with the app that sent the intent.                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                   | ` `[callActivityOnNewIntent](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnNewIntent(android.app.Activity,%20android.content.Intent))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Intent](https://developer.android.com/reference/android/content/Intent)` intent) ` Perform calling of an activity's[Activity.onNewIntent](https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` void`                                                                                                                   | ` `[callActivityOnPause](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnPause(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onPause](https://developer.android.com/reference/android/app/Activity#onPause())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                   | ` `[callActivityOnPictureInPictureRequested](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnPictureInPictureRequested(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onPictureInPictureRequested](https://developer.android.com/reference/android/app/Activity#onPictureInPictureRequested())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                   | ` `[callActivityOnPostCreate](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnPostCreate(android.app.Activity,%20android.os.Bundle,%20android.os.PersistableBundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` savedInstanceState, `[PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle)` persistentState) ` Perform calling of an activity's[Activity.onPostCreate](https://developer.android.com/reference/android/app/Activity#onPostCreate(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                   | ` `[callActivityOnPostCreate](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnPostCreate(android.app.Activity,%20android.os.Bundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` savedInstanceState) ` Perform calling of an activity's[Activity.onPostCreate](https://developer.android.com/reference/android/app/Activity#onPostCreate(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                                   | ` `[callActivityOnRestart](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnRestart(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onRestart](https://developer.android.com/reference/android/app/Activity#onRestart())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` void`                                                                                                                   | ` `[callActivityOnRestoreInstanceState](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnRestoreInstanceState(android.app.Activity,%20android.os.Bundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` savedInstanceState) ` Perform calling of an activity's[Activity.onRestoreInstanceState](https://developer.android.com/reference/android/app/Activity#onRestoreInstanceState(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                   | ` `[callActivityOnRestoreInstanceState](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnRestoreInstanceState(android.app.Activity,%20android.os.Bundle,%20android.os.PersistableBundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` savedInstanceState, `[PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle)` persistentState) ` Perform calling of an activity's[Activity.onRestoreInstanceState](https://developer.android.com/reference/android/app/Activity#onRestoreInstanceState(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[callActivityOnResume](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnResume(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onResume](https://developer.android.com/reference/android/app/Activity#onResume())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                                   | ` `[callActivityOnSaveInstanceState](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnSaveInstanceState(android.app.Activity,%20android.os.Bundle,%20android.os.PersistableBundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` outState, `[PersistableBundle](https://developer.android.com/reference/android/os/PersistableBundle)` outPersistentState) ` Perform calling of an activity's[Activity.onSaveInstanceState](https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                                   | ` `[callActivityOnSaveInstanceState](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnSaveInstanceState(android.app.Activity,%20android.os.Bundle))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` outState) ` Perform calling of an activity's[Activity.onSaveInstanceState](https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle))method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`                                                                                                                   | ` `[callActivityOnStart](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnStart(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onStart](https://developer.android.com/reference/android/app/Activity#onStart())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                   | ` `[callActivityOnStop](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnStop(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onStop](https://developer.android.com/reference/android/app/Activity#onStop())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                   | ` `[callActivityOnUserLeaving](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnUserLeaving(android.app.Activity))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` activity) ` Perform calling of an activity's[Activity.onUserLeaveHint](https://developer.android.com/reference/android/app/Activity#onUserLeaveHint())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                   | ` `[callApplicationOnCreate](https://developer.android.com/reference/android/app/Instrumentation#callApplicationOnCreate(android.app.Application))`(`[Application](https://developer.android.com/reference/android/app/Application)` app) ` Perform calling of the application's[Application.onCreate](https://developer.android.com/reference/android/app/Application#onCreate())method.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` boolean`                                                                                                                | ` `[checkMonitorHit](https://developer.android.com/reference/android/app/Instrumentation#checkMonitorHit(android.app.Instrumentation.ActivityMonitor,%20int))`(`[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)` monitor, int minHits) ` Test whether an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)has been hit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` void`                                                                                                                   | ` `[endPerformanceSnapshot](https://developer.android.com/reference/android/app/Instrumentation#endPerformanceSnapshot())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                                   | ` `[finish](https://developer.android.com/reference/android/app/Instrumentation#finish(int,%20android.os.Bundle))`(int resultCode, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` Terminate instrumentation of the application.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)                                                    | ` `[getAllocCounts](https://developer.android.com/reference/android/app/Instrumentation#getAllocCounts())`() ` Returns a bundle with the current results from the allocation counting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)                                                    | ` `[getBinderCounts](https://developer.android.com/reference/android/app/Instrumentation#getBinderCounts())`() ` Returns a bundle with the counts for various binder counts for this process.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` `[ComponentName](https://developer.android.com/reference/android/content/ComponentName)                                 | ` `[getComponentName](https://developer.android.com/reference/android/app/Instrumentation#getComponentName())`() ` Returns complete component name of this instrumentation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` `[Context](https://developer.android.com/reference/android/content/Context)                                             | ` `[getContext](https://developer.android.com/reference/android/app/Instrumentation#getContext())`() ` Return the Context of this instrumentation's package.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                                     | ` `[getProcessName](https://developer.android.com/reference/android/app/Instrumentation#getProcessName())`() ` Return the name of the process this instrumentation is running in.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` `[Context](https://developer.android.com/reference/android/content/Context)                                             | ` `[getTargetContext](https://developer.android.com/reference/android/app/Instrumentation#getTargetContext())`() ` Return a Context for the target application being instrumented.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` `[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)                                       | ` `[getUiAutomation](https://developer.android.com/reference/android/app/Instrumentation#getUiAutomation(int))`(int flags) ` Gets the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)instance with flags set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` `[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)                                       | ` `[getUiAutomation](https://developer.android.com/reference/android/app/Instrumentation#getUiAutomation())`() ` Gets the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)instance with no flags set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                                                                | ` `[invokeContextMenuAction](https://developer.android.com/reference/android/app/Instrumentation#invokeContextMenuAction(android.app.Activity,%20int,%20int))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` targetActivity, int id, int flag) ` Show the context menu for the currently focused view and executes a particular context menu item.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` boolean`                                                                                                                | ` `[invokeMenuActionSync](https://developer.android.com/reference/android/app/Instrumentation#invokeMenuActionSync(android.app.Activity,%20int,%20int))`(`[Activity](https://developer.android.com/reference/android/app/Activity)` targetActivity, int id, int flag) ` Execute a particular menu item.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` boolean`                                                                                                                | ` `[isProfiling](https://developer.android.com/reference/android/app/Instrumentation#isProfiling())`() ` Check whether this instrumentation was started with profiling enabled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[newActivity](https://developer.android.com/reference/android/app/Instrumentation#newActivity(java.lang.Class<?>,%20android.content.Context,%20android.os.IBinder,%20android.app.Application,%20android.content.Intent,%20android.content.pm.ActivityInfo,%20java.lang.CharSequence,%20android.app.Activity,%20java.lang.String,%20java.lang.Object))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> clazz, `[Context](https://developer.android.com/reference/android/content/Context)` context, `[IBinder](https://developer.android.com/reference/android/os/IBinder)` token, `[Application](https://developer.android.com/reference/android/app/Application)` application, `[Intent](https://developer.android.com/reference/android/content/Intent)` intent, `[ActivityInfo](https://developer.android.com/reference/android/content/pm/ActivityInfo)` info, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` title, `[Activity](https://developer.android.com/reference/android/app/Activity)` parent, `[String](https://developer.android.com/reference/java/lang/String)` id, `[Object](https://developer.android.com/reference/java/lang/Object)` lastNonConfigurationInstance) ` Perform instantiation of an[Activity](https://developer.android.com/reference/android/app/Activity)object. |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[newActivity](https://developer.android.com/reference/android/app/Instrumentation#newActivity(java.lang.ClassLoader,%20java.lang.String,%20android.content.Intent))`(`[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)` cl, `[String](https://developer.android.com/reference/java/lang/String)` className, `[Intent](https://developer.android.com/reference/android/content/Intent)` intent) ` Perform instantiation of the process's[Activity](https://developer.android.com/reference/android/app/Activity)object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` `[Application](https://developer.android.com/reference/android/app/Application)                                         | ` `[newApplication](https://developer.android.com/reference/android/app/Instrumentation#newApplication(java.lang.ClassLoader,%20java.lang.String,%20android.content.Context))`(`[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)` cl, `[String](https://developer.android.com/reference/java/lang/String)` className, `[Context](https://developer.android.com/reference/android/content/Context)` context) ` Perform instantiation of the process's[Application](https://developer.android.com/reference/android/app/Application)object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` static `[Application](https://developer.android.com/reference/android/app/Application)                                  | ` `[newApplication](https://developer.android.com/reference/android/app/Instrumentation#newApplication(java.lang.Class<?>,%20android.content.Context))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<?> clazz, `[Context](https://developer.android.com/reference/android/content/Context)` context) ` Perform instantiation of the process's[Application](https://developer.android.com/reference/android/app/Application)object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` void`                                                                                                                   | ` `[onCreate](https://developer.android.com/reference/android/app/Instrumentation#onCreate(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` arguments) ` Called when the instrumentation is starting, before any application code has been loaded.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                                                                   | ` `[onDestroy](https://developer.android.com/reference/android/app/Instrumentation#onDestroy())`() ` Called when the instrumented application is stopping, after all of the normal application cleanup has occurred.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` boolean`                                                                                                                | ` `[onException](https://developer.android.com/reference/android/app/Instrumentation#onException(java.lang.Object,%20java.lang.Throwable))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj, `[Throwable](https://developer.android.com/reference/java/lang/Throwable)` e) ` This is called whenever the system captures an unhandled exception that was thrown by the application.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                                                                   | ` `[onStart](https://developer.android.com/reference/android/app/Instrumentation#onStart())`() ` Method where the instrumentation thread enters execution.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[removeMonitor](https://developer.android.com/reference/android/app/Instrumentation#removeMonitor(android.app.Instrumentation.ActivityMonitor))`(`[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)` monitor) ` Remove an[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)that was previously added with[addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor)).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` void`                                                                                                                   | ` `[resetInTouchMode](https://developer.android.com/reference/android/app/Instrumentation#resetInTouchMode())`() ` Resets the[touch mode](https://developer.android.com/reference/android/app/Instrumentation#setInTouchMode(boolean))to the device default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                                                                   | ` `[runOnMainSync](https://developer.android.com/reference/android/app/Instrumentation#runOnMainSync(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable)` runner) ` Execute a call on the application's main thread, blocking until it is complete.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` void`                                                                                                                   | ` `[sendCharacterSync](https://developer.android.com/reference/android/app/Instrumentation#sendCharacterSync(int))`(int keyCode) ` Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[sendKeyDownUpSync](https://developer.android.com/reference/android/app/Instrumentation#sendKeyDownUpSync(int))`(int keyCode) ` Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[sendKeySync](https://developer.android.com/reference/android/app/Instrumentation#sendKeySync(android.view.KeyEvent))`(`[KeyEvent](https://developer.android.com/reference/android/view/KeyEvent)` event) ` Sends a key event to the currently focused window, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` void`                                                                                                                   | ` `[sendPointerSync](https://developer.android.com/reference/android/app/Instrumentation#sendPointerSync(android.view.MotionEvent))`(`[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)` event) ` Dispatches a pointer event into a window owned by the instrumented application, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                                                                   | ` `[sendStatus](https://developer.android.com/reference/android/app/Instrumentation#sendStatus(int,%20android.os.Bundle))`(int resultCode, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` results) ` Provide a status report about the application.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` void`                                                                                                                   | ` `[sendStringSync](https://developer.android.com/reference/android/app/Instrumentation#sendStringSync(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` text) ` Sends the key events that result in the given text being typed into the currently focused window, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` void`                                                                                                                   | ` `[sendTrackballEventSync](https://developer.android.com/reference/android/app/Instrumentation#sendTrackballEventSync(android.view.MotionEvent))`(`[MotionEvent](https://developer.android.com/reference/android/view/MotionEvent)` event) ` Dispatches a trackball event into the currently focused window, and waits for it to be processed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                                                                   | ` `[setAutomaticPerformanceSnapshots](https://developer.android.com/reference/android/app/Instrumentation#setAutomaticPerformanceSnapshots())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                   | ` `[setInTouchMode](https://developer.android.com/reference/android/app/Instrumentation#setInTouchMode(boolean))`(boolean inTouch) ` Force the global system in or out of touch mode.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` void`                                                                                                                   | ` `[start](https://developer.android.com/reference/android/app/Instrumentation#start())`() ` Create and start a new thread in which to run instrumentation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[startActivitySync](https://developer.android.com/reference/android/app/Instrumentation#startActivitySync(android.content.Intent,%20android.os.Bundle))`(`[Intent](https://developer.android.com/reference/android/content/Intent)` intent, `[Bundle](https://developer.android.com/reference/android/os/Bundle)` options) ` Start a new activity and wait for it to begin running before returning.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[startActivitySync](https://developer.android.com/reference/android/app/Instrumentation#startActivitySync(android.content.Intent))`(`[Intent](https://developer.android.com/reference/android/content/Intent)` intent) ` Start a new activity and wait for it to begin running before returning.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` void`                                                                                                                   | ` `[startAllocCounting](https://developer.android.com/reference/android/app/Instrumentation#startAllocCounting())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                                   | ` `[startPerformanceSnapshot](https://developer.android.com/reference/android/app/Instrumentation#startPerformanceSnapshot())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                   | ` `[startProfiling](https://developer.android.com/reference/android/app/Instrumentation#startProfiling())`() ` This method will start profiling if isProfiling() returns true.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` void`                                                                                                                   | ` `[stopAllocCounting](https://developer.android.com/reference/android/app/Instrumentation#stopAllocCounting())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` void`                                                                                                                   | ` `[stopProfiling](https://developer.android.com/reference/android/app/Instrumentation#stopProfiling())`() ` Stops profiling if isProfiling() returns true.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` void`                                                                                                                   | ` `[waitForIdle](https://developer.android.com/reference/android/app/Instrumentation#waitForIdle(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable)` recipient) ` Schedule a callback for when the application's main thread goes idle (has no more events to process).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                   | ` `[waitForIdleSync](https://developer.android.com/reference/android/app/Instrumentation#waitForIdleSync())`() ` Synchronously wait for the application to be idle.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[waitForMonitor](https://developer.android.com/reference/android/app/Instrumentation#waitForMonitor(android.app.Instrumentation.ActivityMonitor))`(`[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)` monitor) ` Wait for an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)to be hit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                                               | ` `[waitForMonitorWithTimeout](https://developer.android.com/reference/android/app/Instrumentation#waitForMonitorWithTimeout(android.app.Instrumentation.ActivityMonitor,%20long))`(`[Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)` monitor, long timeOut) ` Wait for an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)to be hit till the timeout expires.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### REPORT_KEY_IDENTIFIER

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String REPORT_KEY_IDENTIFIER
```

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies the class that is writing the report. This can be used to provide more structured logging or reporting capabilities in the IInstrumentationWatcher.

<br />

Constant Value: "id"  

### REPORT_KEY_STREAMRESULT

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final String REPORT_KEY_STREAMRESULT
```

If included in the status or final bundle sent to an IInstrumentationWatcher, this key identifies a string which can simply be printed to the output stream. Using these streams provides a "pretty printer" version of the status \& final packets. Any bundles including this key should also include the complete set of raw key/value pairs, so that the instrumentation can also be launched, and results collected, by an automated system.

<br />

Constant Value: "stream"

## Public constructors

### Instrumentation

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Instrumentation ()
```

<br />

<br />

## Public methods

### acquireLooperManager

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TestLooperManager acquireLooperManager (Looper looper)
```

Takes control of the execution of messages on the specified looper until[TestLooperManager.release](https://developer.android.com/reference/android/os/TestLooperManager#release())is called.

<br />

|        Parameters         ||
|----------|-----------------|
| `looper` | `Looper` <br /> |

|                                              Returns                                              ||
|-------------------------------------------------------------------------------------------|--------|
| [TestLooperManager](https://developer.android.com/reference/android/os/TestLooperManager) | <br /> |

### addMonitor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Instrumentation.ActivityMonitor addMonitor (String cls, 
                Instrumentation.ActivityResult result, 
                boolean block)
```

A convenience wrapper for[addMonitor(android.app.Instrumentation.ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))that creates a class matching[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)for you and returns it.

<br />

|                                                                   Parameters                                                                    ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------|
| `cls`    | `String`: The activity class this monitor is responsible for. <br />                                                                  |
| `result` | `Instrumentation.ActivityResult`: A canned result to return if the monitor is hit; can be null. <br />                                |
| `block`  | `boolean`: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed. <br /> |

|                                                                                   Returns                                                                                    ||
|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|
| [Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor) | The newly created and added activity monitor. <br /> |

**See also:**

- [addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))
- [checkMonitorHit(ActivityMonitor, int)](https://developer.android.com/reference/android/app/Instrumentation#checkMonitorHit(android.app.Instrumentation.ActivityMonitor,%20int))  

### addMonitor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Instrumentation.ActivityMonitor addMonitor (IntentFilter filter, 
                Instrumentation.ActivityResult result, 
                boolean block)
```

A convenience wrapper for[addMonitor(android.app.Instrumentation.ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))that creates an intent filter matching[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)for you and returns it.

<br />

|                                                                   Parameters                                                                    ||
|----------|---------------------------------------------------------------------------------------------------------------------------------------|
| `filter` | `IntentFilter`: The set of intents this monitor is responsible for. <br />                                                            |
| `result` | `Instrumentation.ActivityResult`: A canned result to return if the monitor is hit; can be null. <br />                                |
| `block`  | `boolean`: Controls whether the monitor should block the activity start (returning its canned result) or let the call proceed. <br /> |

|                                                                                   Returns                                                                                    ||
|------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|
| [Instrumentation.ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor) | The newly created and added activity monitor. <br /> |

**See also:**

- [addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))
- [checkMonitorHit(ActivityMonitor, int)](https://developer.android.com/reference/android/app/Instrumentation#checkMonitorHit(android.app.Instrumentation.ActivityMonitor,%20int))  

### addMonitor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void addMonitor (Instrumentation.ActivityMonitor monitor)
```

Add a new[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)that will be checked whenever an activity is started. The monitor is added after any existing ones; the monitor will be hit only if none of the existing monitors can themselves handle the Intent.

<br />

|                                      Parameters                                      ||
|-----------|---------------------------------------------------------------------------|
| `monitor` | `Instrumentation.ActivityMonitor`: The new ActivityMonitor to see. <br /> |

**See also:**

- [addMonitor(IntentFilter, ActivityResult, boolean)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.content.IntentFilter,%20android.app.Instrumentation.ActivityResult,%20boolean))
- [checkMonitorHit(ActivityMonitor, int)](https://developer.android.com/reference/android/app/Instrumentation#checkMonitorHit(android.app.Instrumentation.ActivityMonitor,%20int))  

### addResults

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void addResults (Bundle results)
```

Report some results in the middle of instrumentation execution. Later results (including those provided by[finish(int, Bundle)](https://developer.android.com/reference/android/app/Instrumentation#finish(int,%20android.os.Bundle))) will be combined with[Bundle.putAll](https://developer.android.com/reference/android/os/Bundle#putAll(android.os.Bundle)).

<br />

|         Parameters         ||
|-----------|-----------------|
| `results` | `Bundle` <br /> |

### callActivityOnCreate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                            Parameters                                             ||
|------------|---------------------------------------------------------------------------------------|
| `activity` | `Activity`: The activity being created. <br />                                        |
| `icicle`   | `Bundle`: The previously frozen state (or null) to pass through to onCreate(). <br /> |

### callActivityOnCreate

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                          Parameters                                          ||
|-------------------|---------------------------------------------------------------------------|
| `activity`        | `Activity`: The activity being created. <br />                            |
| `icicle`          | `Bundle`: The previously frozen state (or null) to pass through to <br /> |
| `persistentState` | `PersistableBundle`: The previously persisted state (or null) <br />      |

### callActivityOnDestroy

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|          Parameters           ||
|------------|-------------------|
| `activity` | `Activity` <br /> |

### callActivityOnNewIntent

Added in[API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnNewIntent (Activity activity, 
                Intent intent, 
                ComponentCaller caller)
```

Same as[callActivityOnNewIntent(android.app.Activity, android.content.Intent)](https://developer.android.com/reference/android/app/Instrumentation#callActivityOnNewIntent(android.app.Activity,%20android.content.Intent)), but with an extra parameter for the[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instance associated with the app that sent the intent.

<br />

|                                                                                                     Parameters                                                                                                      ||
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `activity` | `Activity`: The activity receiving a new Intent. This value cannot be`null`. <br />                                                                                                                     |
| `intent`   | `Intent`: The new intent being received. This value cannot be`null`. <br />                                                                                                                             |
| `caller`   | `ComponentCaller`: The[ComponentCaller](https://developer.android.com/reference/android/app/ComponentCaller)instance that launched the activity with the new intent. This value cannot be`null`. <br /> |

### callActivityOnNewIntent

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnNewIntent (Activity activity, 
                Intent intent)
```

Perform calling of an activity's[Activity.onNewIntent](https://developer.android.com/reference/android/app/Activity#onNewIntent(android.content.Intent))method. The default implementation simply calls through to that method.

<br />

|                             Parameters                              ||
|------------|---------------------------------------------------------|
| `activity` | `Activity`: The activity receiving a new Intent. <br /> |
| `intent`   | `Intent`: The new intent being received. <br />         |

### callActivityOnPause

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onPause](https://developer.android.com/reference/android/app/Activity#onPause())method. The default implementation simply calls through to that method.

<br />

|                        Parameters                         ||
|------------|-----------------------------------------------|
| `activity` | `Activity`: The activity being paused. <br /> |

### callActivityOnPictureInPictureRequested

Added in[API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnPictureInPictureRequested (Activity activity)
```

Perform calling of an activity's[Activity.onPictureInPictureRequested](https://developer.android.com/reference/android/app/Activity#onPictureInPictureRequested())method. The default implementation simply calls through to that method.

<br />

|                                                             Parameters                                                             ||
|------------|------------------------------------------------------------------------------------------------------------------------|
| `activity` | `Activity`: The activity being notified that picture-in-picture is being requested. This value cannot be`null`. <br /> |

### callActivityOnPostCreate

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnPostCreate (Activity activity, 
                Bundle savedInstanceState, 
                PersistableBundle persistentState)
```

Perform calling of an activity's[Activity.onPostCreate](https://developer.android.com/reference/android/app/Activity#onPostCreate(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                                   Parameters                                                    ||
|----------------------|-------------------------------------------------------------------------------------------|
| `activity`           | `Activity`: The activity being created. This value cannot be`null`. <br />                |
| `savedInstanceState` | `Bundle`: The previously frozen state (or null) to pass through to onPostCreate(). <br /> |
| `persistentState`    | `PersistableBundle`: The previously persisted state (or null) <br />                      |

### callActivityOnPostCreate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnPostCreate (Activity activity, 
                Bundle savedInstanceState)
```

Perform calling of an activity's[Activity.onPostCreate](https://developer.android.com/reference/android/app/Activity#onPostCreate(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                                   Parameters                                                   ||
|----------------------|------------------------------------------------------------------------------------------|
| `activity`           | `Activity`: The activity being created. This value cannot be`null`. <br />               |
| `savedInstanceState` | `Bundle`: The previously saved state (or null) to pass through to onPostCreate(). <br /> |

### callActivityOnRestart

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onRestart](https://developer.android.com/reference/android/app/Activity#onRestart())method. The default implementation simply calls through to that method.

<br />

|                          Parameters                          ||
|------------|--------------------------------------------------|
| `activity` | `Activity`: The activity being restarted. <br /> |

### callActivityOnRestoreInstanceState

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnRestoreInstanceState (Activity activity, 
                Bundle savedInstanceState)
```

Perform calling of an activity's[Activity.onRestoreInstanceState](https://developer.android.com/reference/android/app/Activity#onRestoreInstanceState(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                                  Parameters                                                   ||
|----------------------|-----------------------------------------------------------------------------------------|
| `activity`           | `Activity`: The activity being restored. This value cannot be`null`. <br />             |
| `savedInstanceState` | `Bundle`: The previously saved state being restored. This value cannot be`null`. <br /> |

### callActivityOnRestoreInstanceState

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnRestoreInstanceState (Activity activity, 
                Bundle savedInstanceState, 
                PersistableBundle persistentState)
```

Perform calling of an activity's[Activity.onRestoreInstanceState](https://developer.android.com/reference/android/app/Activity#onRestoreInstanceState(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                            Parameters                                             ||
|----------------------|-----------------------------------------------------------------------------|
| `activity`           | `Activity`: The activity being restored. This value cannot be`null`. <br /> |
| `savedInstanceState` | `Bundle`: The previously saved state being restored (or null). <br />       |
| `persistentState`    | `PersistableBundle`: The previously persisted state (or null) <br />        |

### callActivityOnResume

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onResume](https://developer.android.com/reference/android/app/Activity#onResume())method. The default implementation simply calls through to that method.

<br />

|                         Parameters                         ||
|------------|------------------------------------------------|
| `activity` | `Activity`: The activity being resumed. <br /> |

### callActivityOnSaveInstanceState

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnSaveInstanceState (Activity activity, 
                Bundle outState, 
                PersistableBundle outPersistentState)
```

Perform calling of an activity's[Activity.onSaveInstanceState](https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                                        Parameters                                                        ||
|----------------------|----------------------------------------------------------------------------------------------------|
| `activity`           | `Activity`: The activity being saved. This value cannot be`null`. <br />                           |
| `outState`           | `Bundle`: The bundle to pass to the call. This value cannot be`null`. <br />                       |
| `outPersistentState` | `PersistableBundle`: The persistent bundle to pass to the call. This value cannot be`null`. <br /> |

### callActivityOnSaveInstanceState

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnSaveInstanceState (Activity activity, 
                Bundle outState)
```

Perform calling of an activity's[Activity.onSaveInstanceState](https://developer.android.com/reference/android/app/Activity#onSaveInstanceState(android.os.Bundle))method. The default implementation simply calls through to that method.

<br />

|                                        Parameters                                        ||
|------------|------------------------------------------------------------------------------|
| `activity` | `Activity`: The activity being saved. This value cannot be`null`. <br />     |
| `outState` | `Bundle`: The bundle to pass to the call. This value cannot be`null`. <br /> |

### callActivityOnStart

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onStart](https://developer.android.com/reference/android/app/Activity#onStart())method. The default implementation simply calls through to that method.

<br />

|                         Parameters                         ||
|------------|------------------------------------------------|
| `activity` | `Activity`: The activity being started. <br /> |

### callActivityOnStop

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of an activity's[Activity.onStop](https://developer.android.com/reference/android/app/Activity#onStop())method. The default implementation simply calls through to that method.

<br />

|                         Parameters                         ||
|------------|------------------------------------------------|
| `activity` | `Activity`: The activity being stopped. <br /> |

### callActivityOnUserLeaving

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void callActivityOnUserLeaving (Activity activity)
```

Perform calling of an activity's[Activity.onUserLeaveHint](https://developer.android.com/reference/android/app/Activity#onUserLeaveHint())method. The default implementation simply calls through to that method.

<br />

|                                         Parameters                                          ||
|------------|---------------------------------------------------------------------------------|
| `activity` | `Activity`: The activity being notified that the user has navigated away <br /> |

### callApplicationOnCreate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform calling of the application's[Application.onCreate](https://developer.android.com/reference/android/app/Application#onCreate())method. The default implementation simply calls through to that method.

Note: This method will be called immediately after[onCreate(android.os.Bundle)](https://developer.android.com/reference/android/app/Instrumentation#onCreate(android.os.Bundle)). Often instrumentation tests start their test thread in onCreate(); you need to be careful of races between these. (Well between it and everything else, but let's start here.)

<br />

|                         Parameters                          ||
|-------|------------------------------------------------------|
| `app` | `Application`: The application being created. <br /> |

### checkMonitorHit

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean checkMonitorHit (Instrumentation.ActivityMonitor monitor, 
                int minHits)
```

Test whether an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)has been hit. If the monitor has been hit at least<var translate="no">minHits</var>times, then it will be removed from the activity monitor list and true returned. Otherwise it is left as-is and false is returned.

<br />

|                                     Parameters                                     ||
|-----------|-------------------------------------------------------------------------|
| `monitor` | `Instrumentation.ActivityMonitor`: The ActivityMonitor to check. <br /> |
| `minHits` | `int`: The minimum number of hits required. <br />                      |

|                                Returns                                ||
|-----------|------------------------------------------------------------|
| `boolean` | True if the hit count has been reached, else false. <br /> |

**See also:**

- [addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))  

### endPerformanceSnapshot

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void endPerformanceSnapshot ()
```

<br />

<br />

### finish

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Terminate instrumentation of the application. This will cause the application process to exit, removing this instrumentation from the next time the application is started. If multiple processes are currently running for this instrumentation, all of those processes will be killed.

<br />

|                                              Parameters                                               ||
|--------------|-----------------------------------------------------------------------------------------|
| `resultCode` | `int`: Overall success/failure of instrumentation. <br />                               |
| `results`    | `Bundle`: Any results to send back to the code that started the instrumentation. <br /> |

### getAllocCounts

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Bundle getAllocCounts ()
```

Returns a bundle with the current results from the allocation counting.

<br />

|                                   Returns                                   ||
|---------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle) | <br /> |

### getBinderCounts

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Bundle getBinderCounts ()
```

Returns a bundle with the counts for various binder counts for this process. Currently the only two that are reported are the number of send and the number of received transactions.

<br />

|                                   Returns                                   ||
|---------------------------------------------------------------------|--------|
| [Bundle](https://developer.android.com/reference/android/os/Bundle) | <br /> |

### getComponentName

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public ComponentName getComponentName ()
```

Returns complete component name of this instrumentation.

<br />

|                                                                           Returns                                                                            ||
|----------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [ComponentName](https://developer.android.com/reference/android/content/ComponentName) | Returns the complete component name for this instrumentation. <br /> |

### getContext

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Context getContext ()
```

Return the Context of this instrumentation's package. Note that this is often different than the Context of the application being instrumentated, since the instrumentation code often lives is a different package than that of the application it is running against. See[getTargetContext()](https://developer.android.com/reference/android/app/Instrumentation#getTargetContext())to retrieve a Context for the target application.

<br />

|                                                          Returns                                                          ||
|----------------------------------------------------------------------------|-----------------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context) | The instrumentation's package context. <br /> |

**See also:**

- [getTargetContext()](https://developer.android.com/reference/android/app/Instrumentation#getTargetContext())  

### getProcessName

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getProcessName ()
```

Return the name of the process this instrumentation is running in. Note this should only be used for testing and debugging. If you are thinking about using this to, for example, conditionalize what is initialized in an Application class, it is strongly recommended to instead use lazy initialization (such as a getter for the state that only creates it when requested). This can greatly reduce the work your process does when created for secondary things, such as to receive a broadcast.

<br />

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### getTargetContext

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Context getTargetContext ()
```

Return a Context for the target application being instrumented. Note that this is often different than the Context of the instrumentation code, since the instrumentation code often lives is a different package than that of the application it is running against. See[getContext()](https://developer.android.com/reference/android/app/Instrumentation#getContext())to retrieve a Context for the instrumentation code.

<br />

|                                                         Returns                                                         ||
|----------------------------------------------------------------------------|---------------------------------------------|
| [Context](https://developer.android.com/reference/android/content/Context) | A Context in the target application. <br /> |

**See also:**

- [getContext()](https://developer.android.com/reference/android/app/Instrumentation#getContext())  

### getUiAutomation

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public UiAutomation getUiAutomation (int flags)
```

Gets the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)instance with flags set.

**Note:** The APIs exposed via the returned[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)work across application boundaries while the APIs exposed by the instrumentation do not. For example,[Instrumentation.sendPointerSync(MotionEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendPointerSync(android.view.MotionEvent))will not allow you to inject the event in an app different from the instrumentation target, while[UiAutomation.injectInputEvent(android.view.InputEvent, boolean)](https://developer.android.com/reference/android/app/UiAutomation#injectInputEvent(android.view.InputEvent,%20boolean))will work regardless of the current application.

A typical test case should be using either the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)or[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation)APIs. Using both APIs at the same time is not a mistake by itself but a client has to be aware of the APIs limitations.

If a[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)exists with different flags, the flags on that instance will be changed, and then it will be returned.

Compatibility mode: This method is infallible for apps targeted for[Build.VERSION_CODES.R](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)and earlier versions; for apps targeted for later versions, it will return null if[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)fails to connect. The caller can check the return value and retry on error.

<br />

<br />

|                                                                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                                                                        ||
|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `flags` | `int`: The flags to be passed to the UiAutomation, for example[UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES),[UiAutomation.FLAG_DONT_USE_ACCESSIBILITY](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_USE_ACCESSIBILITY). Value is 0,[UiAutomation.FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES), or[UiAutomation.FLAG_DONT_USE_ACCESSIBILITY](https://developer.android.com/reference/android/app/UiAutomation#FLAG_DONT_USE_ACCESSIBILITY) <br /> |

|                                                       Returns                                                        ||
|----------------------------------------------------------------------------------|------------------------------------|
| [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) | The UI automation instance. <br /> |

**See also:**

- [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)  

### getUiAutomation

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public UiAutomation getUiAutomation ()
```

Gets the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)instance with no flags set.

**Note:** The APIs exposed via the returned[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)work across application boundaries while the APIs exposed by the instrumentation do not. For example,[Instrumentation.sendPointerSync(MotionEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendPointerSync(android.view.MotionEvent))will not allow you to inject the event in an app different from the instrumentation target, while[UiAutomation.injectInputEvent(android.view.InputEvent, boolean)](https://developer.android.com/reference/android/app/UiAutomation#injectInputEvent(android.view.InputEvent,%20boolean))will work regardless of the current application.

A typical test case should be using either the[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)or[Instrumentation](https://developer.android.com/reference/android/app/Instrumentation)APIs. Using both APIs at the same time is not a mistake by itself but a client has to be aware of the APIs limitations.

Equivalent to`getUiAutomation(0)`. If a[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)exists with different flags, the flags on that instance will be changed, and then it will be returned.

Compatibility mode: This method is infallible for apps targeted for[Build.VERSION_CODES.R](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)and earlier versions; for apps targeted for later versions, it will return null if[UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)fails to connect. The caller can check the return value and retry on error.

<br />

<br />

|                                                       Returns                                                        ||
|----------------------------------------------------------------------------------|------------------------------------|
| [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation) | The UI automation instance. <br /> |

**See also:**

- [UiAutomation](https://developer.android.com/reference/android/app/UiAutomation)  

### invokeContextMenuAction

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean invokeContextMenuAction (Activity targetActivity, 
                int id, 
                int flag)
```

Show the context menu for the currently focused view and executes a particular context menu item.

<br />

|                                      Parameters                                       ||
|------------------|---------------------------------------------------------------------|
| `targetActivity` | `Activity`: The activity in question. <br />                        |
| `id`             | `int`: The identifier associated with the context menu item. <br /> |
| `flag`           | `int`: Additional flags, if any. <br />                             |

|                                                    Returns                                                    ||
|-----------|----------------------------------------------------------------------------------------------------|
| `boolean` | Whether the invocation was successful (for example, it could be false if item is disabled). <br /> |

### invokeMenuActionSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean invokeMenuActionSync (Activity targetActivity, 
                int id, 
                int flag)
```

Execute a particular menu item.

<br />

|                                  Parameters                                   ||
|------------------|-------------------------------------------------------------|
| `targetActivity` | `Activity`: The activity in question. <br />                |
| `id`             | `int`: The identifier associated with the menu item. <br /> |
| `flag`           | `int`: Additional flags, if any. <br />                     |

|                                                    Returns                                                    ||
|-----------|----------------------------------------------------------------------------------------------------|
| `boolean` | Whether the invocation was successful (for example, it could be false if item is disabled). <br /> |

### isProfiling

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isProfiling ()
```

Check whether this instrumentation was started with profiling enabled.

<br />

|                                      Returns                                       ||
|-----------|-------------------------------------------------------------------------|
| `boolean` | Returns true if profiling was enabled when starting, else false. <br /> |

### newActivity

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform instantiation of an[Activity](https://developer.android.com/reference/android/app/Activity)object. This method is intended for use with unit tests, such as android.test.ActivityUnitTestCase. The activity will be useable locally but will be missing some of the linkages necessary for use within the system.

<br />

|                                                                                                                Parameters                                                                                                                 ||
|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `clazz`                        | `Class`: The Class of the desired Activity <br />                                                                                                                                                         |
| `context`                      | `Context`: The base context for the activity to use <br />                                                                                                                                                |
| `token`                        | `IBinder`: The token for this activity to communicate with <br />                                                                                                                                         |
| `application`                  | `Application`: The application object (if any) <br />                                                                                                                                                     |
| `intent`                       | `Intent`: The intent that started this Activity <br />                                                                                                                                                    |
| `info`                         | `ActivityInfo`: ActivityInfo from the manifest <br />                                                                                                                                                     |
| `title`                        | `CharSequence`: The title, typically retrieved from the ActivityInfo record <br />                                                                                                                        |
| `parent`                       | `Activity`: The parent Activity (if any) <br />                                                                                                                                                           |
| `id`                           | `String`: The embedded Id (if any) <br />                                                                                                                                                                 |
| `lastNonConfigurationInstance` | `Object`: Arbitrary object that will be available via[Activity.getLastNonConfigurationInstance()](https://developer.android.com/reference/android/app/Activity#getLastNonConfigurationInstance()). <br /> |

|                                                      Returns                                                       ||
|--------------------------------------------------------------------------|------------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | Returns the instantiated activity <br /> |

|                                                                Throws                                                                ||
|----------------------------------------------------------------------------------------------------|----------------------------------|
|                                                                                                    | java.lang.InstantiationException |
|                                                                                                    | java.lang.IllegalAccessException |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) |                                  |
| [InstantiationException](https://developer.android.com/reference/java/lang/InstantiationException) |                                  |

### newActivity

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform instantiation of the process's[Activity](https://developer.android.com/reference/android/app/Activity)object. The default implementation provides the normal system behavior.

<br />

|                                              Parameters                                               ||
|-------------|------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The ClassLoader with which to instantiate the object. <br />              |
| `className` | `String`: The name of the class implementing the Activity object. <br />                 |
| `intent`    | `Intent`: The Intent object that specified the activity class being instantiated. <br /> |

|                                                         Returns                                                          ||
|--------------------------------------------------------------------------|------------------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | The newly instantiated Activity object. <br /> |

|                                                Throws                                                 ||
|----------------------------------------------------------------------------------------------------|---|
| [ClassNotFoundException](https://developer.android.com/reference/java/lang/ClassNotFoundException) |   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) |   |
| [InstantiationException](https://developer.android.com/reference/java/lang/InstantiationException) |   |

### newApplication

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Perform instantiation of the process's[Application](https://developer.android.com/reference/android/app/Application)object. The default implementation provides the normal system behavior.

<br />

|                                        Parameters                                        ||
|-------------|-----------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The ClassLoader with which to instantiate the object. <br /> |
| `className` | `String`: The name of the class implementing the Application object. <br /> |
| `context`   | `Context`: The context to initialize the application with <br />            |

|                                                              Returns                                                              ||
|--------------------------------------------------------------------------------|---------------------------------------------------|
| [Application](https://developer.android.com/reference/android/app/Application) | The newly instantiated Application object. <br /> |

|                                                Throws                                                 ||
|----------------------------------------------------------------------------------------------------|---|
| [ClassNotFoundException](https://developer.android.com/reference/java/lang/ClassNotFoundException) |   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) |   |
| [InstantiationException](https://developer.android.com/reference/java/lang/InstantiationException) |   |

### newApplication

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static Application newApplication (Class<?> clazz, 
                Context context)
```

Perform instantiation of the process's[Application](https://developer.android.com/reference/android/app/Application)object. The default implementation provides the normal system behavior.

<br />

|                                   Parameters                                    ||
|-----------|----------------------------------------------------------------------|
| `clazz`   | `Class`: The class used to create an Application object from. <br /> |
| `context` | `Context`: The context to initialize the application with <br />     |

|                                                              Returns                                                              ||
|--------------------------------------------------------------------------------|---------------------------------------------------|
| [Application](https://developer.android.com/reference/android/app/Application) | The newly instantiated Application object. <br /> |

|                                                Throws                                                 ||
|----------------------------------------------------------------------------------------------------|---|
| [ClassNotFoundException](https://developer.android.com/reference/java/lang/ClassNotFoundException) |   |
| [IllegalAccessException](https://developer.android.com/reference/java/lang/IllegalAccessException) |   |
| [InstantiationException](https://developer.android.com/reference/java/lang/InstantiationException) |   |

### onCreate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Called when the instrumentation is starting, before any application code has been loaded. Usually this will be implemented to simply call[start()](https://developer.android.com/reference/android/app/Instrumentation#start())to begin the instrumentation thread, which will then continue execution in[onStart()](https://developer.android.com/reference/android/app/Instrumentation#onStart()).

If you do not need your own thread -- that is you are writing your instrumentation to be completely asynchronous (returning to the event loop so that the application can run), you can simply begin your instrumentation here, for example call[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))to begin the appropriate first activity of the application.

<br />

|                                                   Parameters                                                    ||
|-------------|----------------------------------------------------------------------------------------------------|
| `arguments` | `Bundle`: Any additional arguments that were supplied when the instrumentation was started. <br /> |

### onDestroy

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onDestroy ()
```

Called when the instrumented application is stopping, after all of the normal application cleanup has occurred.

<br />

### onException

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

This is called whenever the system captures an unhandled exception that was thrown by the application. The default implementation simply returns false, allowing normal system handling of the exception to take place.

<br />

|                                                                  Parameters                                                                   ||
|-------|----------------------------------------------------------------------------------------------------------------------------------------|
| `obj` | `Object`: The client object that generated the exception. May be an Application, Activity, BroadcastReceiver, Service, or null. <br /> |
| `e`   | `Throwable`: The exception that was thrown. <br />                                                                                     |

|                                                                              Returns                                                                               ||
|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `boolean` | To allow normal system exception process to occur, return false. If true is returned, the system will proceed as if the exception didn't happen. <br /> |

### onStart

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void onStart ()
```

Method where the instrumentation thread enters execution. This allows you to run your instrumentation code in a separate thread than the application, so that it can perform blocking operation such as[sendKeySync(KeyEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendKeySync(android.view.KeyEvent))or[startActivitySync(Intent)](https://developer.android.com/reference/android/app/Instrumentation#startActivitySync(android.content.Intent)).

You will typically want to call finish() when this function is done, to end your instrumentation.

<br />

### removeMonitor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void removeMonitor (Instrumentation.ActivityMonitor monitor)
```

Remove an[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)that was previously added with[addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor)).

<br />

|                                 Parameters                                  ||
|-----------|------------------------------------------------------------------|
| `monitor` | `Instrumentation.ActivityMonitor`: The monitor to remove. <br /> |

**See also:**

- [addMonitor(ActivityMonitor)](https://developer.android.com/reference/android/app/Instrumentation#addMonitor(android.app.Instrumentation.ActivityMonitor))  

### resetInTouchMode

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void resetInTouchMode ()
```

Resets the[touch mode](https://developer.android.com/reference/android/app/Instrumentation#setInTouchMode(boolean))to the device default.

<br />

### runOnMainSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void runOnMainSync (Runnable runner)
```

Execute a call on the application's main thread, blocking until it is complete. Useful for doing things that are not thread-safe, such as looking at or modifying the view hierarchy.

<br />

|                            Parameters                            ||
|----------|--------------------------------------------------------|
| `runner` | `Runnable`: The code to run on the main thread. <br /> |

### sendCharacterSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendCharacterSync (int keyCode)
```

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

Equivalent to[sendKeyDownUpSync(int)](https://developer.android.com/reference/android/app/Instrumentation#sendKeyDownUpSync(int)).

<br />

|                           Parameters                            ||
|-----------|------------------------------------------------------|
| `keyCode` | `int`: The key code of the character to send. <br /> |

**See also:**

- [sendKeySync(KeyEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendKeySync(android.view.KeyEvent))  

### sendKeyDownUpSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendKeyDownUpSync (int keyCode)
```

Sends up and down key events with the given key code to the currently focused window, and waits for it to be processed.

<br />

|                          Parameters                           ||
|-----------|----------------------------------------------------|
| `keyCode` | `int`: The key code for the events to send. <br /> |

**See also:**

- [sendKeySync(KeyEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendKeySync(android.view.KeyEvent))  

### sendKeySync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendKeySync (KeyEvent event)
```

Sends a key event to the currently focused window, and waits for it to be processed.

This method blocks until the recipient has finished handling the event. Note that the recipient may*not*have completely finished reacting from the event when this method returns. For example, it may still be in the process of updating its display or UI contents upon reacting to the injected event.

<br />

|                             Parameters                              ||
|---------|------------------------------------------------------------|
| `event` | `KeyEvent`: The event to send to the current focus. <br /> |

### sendPointerSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendPointerSync (MotionEvent event)
```

Dispatches a pointer event into a window owned by the instrumented application, and waits for it to be processed.

If the motion event being injected is targeted at a window that is not owned by the instrumented application, the input injection will fail. See[getUiAutomation()](https://developer.android.com/reference/android/app/Instrumentation#getUiAutomation())for injecting events into all windows.

This method blocks until the recipient has finished handling the event. Note that the recipient may*not*have completely finished reacting from the event when this method returns. For example, it may still be in the process of updating its display or UI contents upon reacting to the injected event.

<br />

|                                                                                                                                                                                                     Parameters                                                                                                                                                                                                      ||
|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | `MotionEvent`: A motion event describing the pointer action. (As noted in[MotionEvent.obtain(long, long, int, float, float, int)](https://developer.android.com/reference/android/view/MotionEvent#obtain(long,%20long,%20int,%20float,%20float,%20int)), be sure to use[SystemClock.uptimeMillis()](https://developer.android.com/reference/android/os/SystemClock#uptimeMillis())as the timebase. <br /> |

### sendStatus

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Provide a status report about the application.

<br />

|                                              Parameters                                               ||
|--------------|-----------------------------------------------------------------------------------------|
| `resultCode` | `int`: Current success/failure of instrumentation. <br />                               |
| `results`    | `Bundle`: Any results to send back to the code that started the instrumentation. <br /> |

### sendStringSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendStringSync (String text)
```

Sends the key events that result in the given text being typed into the currently focused window, and waits for it to be processed.

<br />

|                  Parameters                   ||
|--------|---------------------------------------|
| `text` | `String`: The text to be sent. <br /> |

**See also:**

- [sendKeySync(KeyEvent)](https://developer.android.com/reference/android/app/Instrumentation#sendKeySync(android.view.KeyEvent))  

### sendTrackballEventSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void sendTrackballEventSync (MotionEvent event)
```

Dispatches a trackball event into the currently focused window, and waits for it to be processed.

This method blocks until the recipient has finished handling the event. Note that the recipient may*not*have completely finished reacting from the event when this method returns. For example, it may still be in the process of updating its display or UI contents upon reacting to the injected event.

<br />

|                                                                                                                                                                                                      Parameters                                                                                                                                                                                                       ||
|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `event` | `MotionEvent`: A motion event describing the trackball action. (As noted in[MotionEvent.obtain(long, long, int, float, float, int)](https://developer.android.com/reference/android/view/MotionEvent#obtain(long,%20long,%20int,%20float,%20float,%20int)), be sure to use[SystemClock.uptimeMillis()](https://developer.android.com/reference/android/os/SystemClock#uptimeMillis())as the timebase. <br /> |

### setAutomaticPerformanceSnapshots

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setAutomaticPerformanceSnapshots ()
```

<br />

<br />

### setInTouchMode

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setInTouchMode (boolean inTouch)
```

Force the global system in or out of touch mode. This can be used if your instrumentation relies on the UI being in one more or the other when it starts.

**Note:** Starting from Android[Build.VERSION_CODES.TIRAMISU](https://developer.android.com/reference/android/os/Build.VERSION_CODES#TIRAMISU), this method will only take effect if the instrumentation was sourced from a process with`MODIFY_TOUCH_MODE_STATE`internal permission granted (shell already have it).

<br />

|                                        Parameters                                        ||
|-----------|-------------------------------------------------------------------------------|
| `inTouch` | `boolean`: Set to true to be in touch mode, false to be in focus mode. <br /> |

### start

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void start ()
```

Create and start a new thread in which to run instrumentation. This new thread will call to[onStart()](https://developer.android.com/reference/android/app/Instrumentation#onStart())where you can implement the instrumentation.

<br />

### startActivitySync

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Activity startActivitySync (Intent intent, 
                Bundle options)
```

Start a new activity and wait for it to begin running before returning. In addition to being synchronous, this method as some semantic differences from the standard[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))call: the activity component is resolved before talking with the activity manager (its class name is specified in the Intent that this method ultimately starts), and it does not allow you to start activities that run in a different process. In addition, if the given Intent resolves to multiple activities, instead of displaying a dialog for the user to select an activity, an exception will be thrown.

The function returns as soon as the activity goes idle following the call to its[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle)). Generally this means it has gone through the full initialization including[Activity.onResume](https://developer.android.com/reference/android/app/Activity#onResume())and drawn and displayed its initial window.

<br />

|                                                                                                                                                          Parameters                                                                                                                                                          ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `intent`  | `Intent`: Description of the activity to start. This value cannot be`null`. <br />                                                                                                                                                                                                                                |
| `options` | `Bundle`: Additional options for how the Activity should be started. May be null if there are no options. See[ActivityOptions](https://developer.android.com/reference/android/app/ActivityOptions)for how to build the Bundle supplied here; there are no supported definitions for building it manually. <br /> |

|                                                   Returns                                                    ||
|--------------------------------------------------------------------------|------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | This value cannot be`null`. <br /> |

**See also:**

- [Context.startActivity(Intent, Bundle)](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent,%20android.os.Bundle))  

### startActivitySync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Start a new activity and wait for it to begin running before returning. In addition to being synchronous, this method as some semantic differences from the standard[Context.startActivity](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))call: the activity component is resolved before talking with the activity manager (its class name is specified in the Intent that this method ultimately starts), and it does not allow you to start activities that run in a different process. In addition, if the given Intent resolves to multiple activities, instead of displaying a dialog for the user to select an activity, an exception will be thrown.

The function returns as soon as the activity goes idle following the call to its[Activity.onCreate](https://developer.android.com/reference/android/app/Activity#onCreate(android.os.Bundle)). Generally this means it has gone through the full initialization including[Activity.onResume](https://developer.android.com/reference/android/app/Activity#onResume())and drawn and displayed its initial window.

<br />

|                            Parameters                            ||
|----------|--------------------------------------------------------|
| `intent` | `Intent`: Description of the activity to start. <br /> |

|                                     Returns                                      ||
|--------------------------------------------------------------------------|--------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | <br /> |

**See also:**

- [Context.startActivity(Intent)](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))
- [startActivitySync(Intent, Bundle)](https://developer.android.com/reference/android/app/Instrumentation#startActivitySync(android.content.Intent,%20android.os.Bundle))  

### startAllocCounting

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void startAllocCounting ()
```

<br />

<br />

### startPerformanceSnapshot

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void startPerformanceSnapshot ()
```

<br />

<br />

### startProfiling

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void startProfiling ()
```

This method will start profiling if isProfiling() returns true. You should only call this method if you set the handleProfiling attribute in the manifest file for this Instrumentation to true.

<br />

### stopAllocCounting

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void stopAllocCounting ()
```

<br />

<br />

### stopProfiling

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void stopProfiling ()
```

Stops profiling if isProfiling() returns true.

<br />

### waitForIdle

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void waitForIdle (Runnable recipient)
```

Schedule a callback for when the application's main thread goes idle (has no more events to process).

<br />

|                                        Parameters                                        ||
|-------------|-----------------------------------------------------------------------------|
| `recipient` | `Runnable`: Called the next time the thread's message queue is idle. <br /> |

### waitForIdleSync

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void waitForIdleSync ()
```

Synchronously wait for the application to be idle. Can not be called from the main application thread -- use[start()](https://developer.android.com/reference/android/app/Instrumentation#start())to execute instrumentation in its own thread.

<br />

### waitForMonitor

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Activity waitForMonitor (Instrumentation.ActivityMonitor monitor)
```

Wait for an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)to be hit. Once the monitor has been hit, it is removed from the activity monitor list and the first created Activity object that matched it is returned.

<br />

|                                      Parameters                                       ||
|-----------|----------------------------------------------------------------------------|
| `monitor` | `Instrumentation.ActivityMonitor`: The ActivityMonitor to wait for. <br /> |

|                                                            Returns                                                             ||
|--------------------------------------------------------------------------|------------------------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | The Activity object that matched the monitor. <br /> |

### waitForMonitorWithTimeout

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Activity waitForMonitorWithTimeout (Instrumentation.ActivityMonitor monitor, 
                long timeOut)
```

Wait for an existing[ActivityMonitor](https://developer.android.com/reference/android/app/Instrumentation.ActivityMonitor)to be hit till the timeout expires. Once the monitor has been hit, it is removed from the activity monitor list and the first created Activity object that matched it is returned. If the timeout expires, a null object is returned.

<br />

|                                      Parameters                                       ||
|-----------|----------------------------------------------------------------------------|
| `monitor` | `Instrumentation.ActivityMonitor`: The ActivityMonitor to wait for. <br /> |
| `timeOut` | `long`: The timeout value in milliseconds. <br />                          |

|                                                            Returns                                                             ||
|--------------------------------------------------------------------------|------------------------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity) | The Activity object that matched the monitor. <br /> |