# UriIdlingResource

Summary:[Nested Classes](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#nestedclasses)\|[Ctors](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#pubctors)\|[Methods](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#)  

# UriIdlingResource

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

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


``


implements

`[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)`


`

|---|------------------------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.idling.net.UriIdlingResource |

<br />

*** ** * ** ***

An implementation of[IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)useful for monitoring idleness of network traffic.

This is similar to[ERROR(/android.support.test.espresso.contrib.CountingIdlingResource)](https://developer.android.com/), with the additional idleness constraint that the counter must be 0 for a set period of time before the resource becomes idle.

A network timeout is required to be reasonably sure that the webview has finished loading. Imagine the case where each response that comes back causes another request to be made until loading is complete. The counter will go from 0-\>1-\>0-\>1-\>0-\>1..., but we don't want to report the webview as idle each time this happens.

**This API is currently in beta.**

## Summary

|                                                                                  ### Nested classes                                                                                   ||
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [UriIdlingResource.HandlerIntf](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource.HandlerIntf) Wraps a Handler object. |

|                                                                                                                              ### Public constructors                                                                                                                               ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[UriIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#UriIdlingResource(java.lang.String, long))`(`[String](https://developer.android.com/reference/java/lang/String.html)` resourceName, long timeoutMs) ` |

|                                                                                                                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                                                                                                                        ||
|----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                    | ` `[beginLoad](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#beginLoad(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` uri) ` Called when a request is made.                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                    | ` `[endLoad](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#endLoad(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String.html)` uri) ` Called when a request is completed (ie the response is returned).                                                                                                                                                                                                                                                                                      |
| ` `[String](https://developer.android.com/reference/java/lang/String.html) | ` `[getName](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#getName())`() ` Returns the name of the resources (used for logging and idempotency of registration).                                                                                                                                                                                                                                                                                                                                                               |
| ` void`                                                                    | ` `[ignoreUri](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#ignoreUri(java.util.regex.Pattern))`(`[Pattern](https://developer.android.com/reference/java/util/regex/Pattern.html)` pattern) ` Add a regex pattern to the ignore list.                                                                                                                                                                                                                                                                                         |
| ` boolean`                                                                 | ` `[isIdleNow](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#isIdleNow())`() ` Returns`true`if resource is currently idle.                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` void`                                                                    | ` `[registerIdleTransitionCallback](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#registerIdleTransitionCallback(android.support.test.espresso.IdlingResource.ResourceCallback))`(`[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)` resourceCallback) ` Registers the given[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)with the resource. |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource#)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/idling/net/UriIdlingResource#)From interface` `[android.support.test.espresso.IdlingResource](https://developer.android.com/reference/android/support/test/espresso/IdlingResource)` ` |-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract `[String](https://developer.android.com/reference/java/lang/String.html) | ` `[getName](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#getName())`() ` Returns the name of the resources (used for logging and idempotency of registration).                                                                                                                                                                                                                                                                                                                                                       | | ` abstract boolean`                                                                 | ` `[isIdleNow](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#isIdleNow())`() ` Returns`true`if resource is currently idle.                                                                                                                                                                                                                                                                                                                                                                                             | | ` abstract void`                                                                    | ` `[registerIdleTransitionCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource#registerIdleTransitionCallback(android.support.test.espresso.IdlingResource.ResourceCallback))`(`[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)` callback) ` Registers the given[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)with the resource. | ||

## Public constructors

### UriIdlingResource

```
UriIdlingResource (String resourceName, 
                long timeoutMs)
```

<br />

<br />

|           Parameters            ||
|----------------|-----------------|
| `resourceName` | `String` <br /> |
| `timeoutMs`    | `long` <br />   |

## Public methods

### beginLoad

```
void beginLoad (String uri)
```

Called when a request is made.

If the URI is not blacklisted the idle counter is incremented.

<br />

|       Parameters       ||
|-------|-----------------|
| `uri` | `String` <br /> |

### endLoad

```
void endLoad (String uri)
```

Called when a request is completed (ie the response is returned).

If the URI is not blacklisted the idle counter is decremented. Once the idle counter reaches 0, the idle update thread will set the resource as idle after the appropriate timeout.

<br />

|       Parameters       ||
|-------|-----------------|
| `uri` | `String` <br /> |

### getName

```
String getName ()
```

Returns the name of the resources (used for logging and idempotency of registration).

<br />

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

### ignoreUri

```
void ignoreUri (Pattern pattern)
```

Add a regex pattern to the ignore list.

All request URIs are checked against all patterns, and matches are ignored for the purposes of detecting when the webview is idle.

Ignored patterns can only be added when the webview is idle.

<br />

|         Parameters          ||
|-----------|------------------|
| `pattern` | `Pattern` <br /> |

### isIdleNow

```
boolean isIdleNow ()
```

Returns`true`if resource is currently idle. Espresso will**always**call this method from the main thread, therefore it should be non-blocking and return immediately.

<br />

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### registerIdleTransitionCallback

```
void registerIdleTransitionCallback (IdlingResource.ResourceCallback resourceCallback)
```

Registers the given[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)with the resource. Espresso will call this method:

- with its implementation of[IdlingResource.ResourceCallback](https://developer.android.com/reference/android/support/test/espresso/IdlingResource.ResourceCallback)so it can be notified asynchronously that your resource is idle
- from the main thread, but you are free to execute the callback's onTransitionToIdle from any thread
- once (when it is initially given a reference to your IdlingResource)

You only need to call this upon transition from busy to idle - if the resource is already idle when the method is called invoking the call back is optional and has no significant impact.

<br />

|                          Parameters                          ||
|--------------------|------------------------------------------|
| `resourceCallback` | `IdlingResource.ResourceCallback` <br /> |

-

  ## Interfaces

  - [UriIdlingResource.HandlerIntf](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource.HandlerIntf)
-

  ## Classes

  - [UriIdlingResource](https://developer.android.com/reference/android/support/test/espresso/idling/net/UriIdlingResource)