# IntentsTestRule

Summary:[Ctors](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#pubctors)\|[Protected Methods](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#promethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#)  

# IntentsTestRule

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public


class
IntentsTestRule
`  
`


``

extends `[ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule)`<T extends `[Activity](https://developer.android.com/reference/android/app/Activity.html)`>


``


`

|---|---|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)                                                                                     |||
| ↳ | [android.support.test.rule.ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule)\<T extends[android.app.Activity](https://developer.android.com/reference/android/app/Activity.html)\> ||
|   | ↳ | android.support.test.espresso.intent.rule.IntentsTestRule\<T extends[android.app.Activity](https://developer.android.com/reference/android/app/Activity.html)\> |

<br />

*** ** * ** ***

This rule makes it easy to use Espresso-Intents APIs in functional UI tests. This class is an extension of[ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule), which initializes Espresso-Intents before each test annotated with[`Test`](http://junit.org/javadoc/latest/org/junit/Test.html)and releases Espresso-Intents after each test run. The Activity will be terminated after each test and this rule can be used in the same way as[ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule).

Espresso-Intents APIs can be used in two ways:

- Intent Verification, using the[intended(Matcher)](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#intended(org.hamcrest.Matcher<android.content.Intent>))API
- Intent Stubbing, using the[intending(Matcher)](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#intending(org.hamcrest.Matcher<android.content.Intent>))API

<br />

## Summary

|                                                                                                                                                     ### Public constructors                                                                                                                                                     ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[IntentsTestRule](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>))`(`[Class](https://developer.android.com/reference/java/lang/Class.html)`<T> activityClass) `                                                                     |
| ` `[IntentsTestRule](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>, boolean))`(`[Class](https://developer.android.com/reference/java/lang/Class.html)`<T> activityClass, boolean initialTouchMode) `                                  |
| ` `[IntentsTestRule](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#IntentsTestRule(java.lang.Class<T>, boolean, boolean))`(`[Class](https://developer.android.com/reference/java/lang/Class.html)`<T> activityClass, boolean initialTouchMode, boolean launchActivity) ` |

|                                                                                                                                                                                                                         ### Protected methods                                                                                                                                                                                                                          ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void` | ` `[afterActivityFinished](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#afterActivityFinished())`() ` Override this method to execute any code that should run after the currently launched[Activity](https://developer.android.com/reference/android/app/Activity.html)is finished.                                                                                                                     |
| ` void` | ` `[afterActivityLaunched](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#afterActivityLaunched())`() ` Override this method to execute any code that should run after your[Activity](https://developer.android.com/reference/android/app/Activity.html)is launched, but before any test code is run including any method annotated with[`Before`](http://junit.source.net/javadoc/org/junit/Before.html). |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#)From class` `[android.support.test.rule.ActivityTestRule](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule)` ` |------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` void`                                                                                                                      | ` `[afterActivityFinished](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#afterActivityFinished())`() ` Override this method to execute any code that should run after the currently launched[Activity](https://developer.android.com/reference/android/app/Activity.html)is finished.                                                                                                                     | | ` void`                                                                                                                      | ` `[afterActivityLaunched](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#afterActivityLaunched())`() ` Override this method to execute any code that should run after your[Activity](https://developer.android.com/reference/android/app/Activity.html)is launched, but before any test code is run including any method annotated with[`Before`](http://junit.source.net/javadoc/org/junit/Before.html). | | ` Statement`                                                                                                                 | ` `[apply](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#apply(org.junit.runners.model.Statement, org.junit.runner.Description))`(Statement base, Description description) `                                                                                                                                                                                                                              | | ` void`                                                                                                                      | ` `[beforeActivityLaunched](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#beforeActivityLaunched())`() ` Override this method to execute any code that should run before your[Activity](https://developer.android.com/reference/android/app/Activity.html)is created and launched.                                                                                                                        | | ` void`                                                                                                                      | ` `[finishActivity](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#finishActivity())`() ` Finishes the currently launched Activity.                                                                                                                                                                                                                                                                        | | ` T`                                                                                                                         | ` `[getActivity](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#getActivity())`() ` Returns the reference to the activity under test.                                                                                                                                                                                                                                                                      | | ` `[Intent](https://developer.android.com/reference/android/content/Intent.html)                                             | ` `[getActivityIntent](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#getActivityIntent())`() ` Override this method to set up a custom Intent as if supplied to[startActivity(Intent)](https://developer.android.com/reference/android/content/Context.html#startActivity(android.content.Intent)).                                                                                                       | | ` `[Instrumentation.ActivityResult](https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html) | ` `[getActivityResult](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#getActivityResult())`() ` This method can be used to retrieve the[Instrumentation.ActivityResult](https://developer.android.com/reference/android/app/Instrumentation.ActivityResult.html)of an Activity that has called[setResult(int)](https://developer.android.com/reference/android/app/Activity.html#setResult(int)).          | | ` T`                                                                                                                         | ` `[launchActivity](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#launchActivity(android.content.Intent))`(`[Intent](https://developer.android.com/reference/android/content/Intent.html)` startIntent) ` Launches the Activity under test.                                                                                                                                                               | | ` void`                                                                                                                      | ` `[runOnUiThread](https://developer.android.com/reference/android/support/test/rule/ActivityTestRule#runOnUiThread(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable.html)` runnable) ` Helper method for running part of a method on the UI thread, blocking until it is complete.                                                                                                                | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule#)From interface` org.junit.rules.TestRule ` |-----------------------|---------------------------------------------| | ` abstract Statement` | ` apply(Statement arg0, Description arg1) ` | ||

## Public constructors

### IntentsTestRule

```
IntentsTestRule (Class<T> activityClass)
```

<br />

<br />

|           Parameters            ||
|-----------------|----------------|
| `activityClass` | `Class` <br /> |

### IntentsTestRule

```
IntentsTestRule (Class<T> activityClass, 
                boolean initialTouchMode)
```

<br />

<br />

|              Parameters              ||
|--------------------|------------------|
| `activityClass`    | `Class` <br />   |
| `initialTouchMode` | `boolean` <br /> |

### IntentsTestRule

```
IntentsTestRule (Class<T> activityClass, 
                boolean initialTouchMode, 
                boolean launchActivity)
```

<br />

<br />

|              Parameters              ||
|--------------------|------------------|
| `activityClass`    | `Class` <br />   |
| `initialTouchMode` | `boolean` <br /> |
| `launchActivity`   | `boolean` <br /> |

## Protected methods

### afterActivityFinished

```
void afterActivityFinished ()
```

Override this method to execute any code that should run after the currently launched[Activity](https://developer.android.com/reference/android/app/Activity.html)is finished. This method is called after each test method, including any method annotated with[`After
`](http://junit.source.net/javadoc/org/junit/After.html).

Prefer[`Before
`](http://junit.source.net/javadoc/org/junit/After.html)over this method. This method should usually not be overwritten directly in tests and only be used by subclasses of ActivityTestRule to get notified when the activity is created and visible but test runs.

<br />

### afterActivityLaunched

```
void afterActivityLaunched ()
```

Override this method to execute any code that should run after your[Activity](https://developer.android.com/reference/android/app/Activity.html)is launched, but before any test code is run including any method annotated with[`Before`](http://junit.source.net/javadoc/org/junit/Before.html).

Prefer[`Before
`](http://junit.source.net/javadoc/org/junit/Before.html)over this method. This method should usually not be overwritten directly in tests and only be used by subclasses of ActivityTestRule to get notified when the activity is created and visible but test runs.

<br />

-

  ## Classes

  - [IntentsTestRule](https://developer.android.com/reference/android/support/test/espresso/intent/rule/IntentsTestRule)