# SingleActivityFactory

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

*** ** * ** ***


```
public abstract class SingleActivityFactory<T extends Activity> implements InterceptingActivityFactory
```

<br />

*** ** * ** ***

Abstract implementation of `https://developer.android.com/reference/androidx/test/runner/intercepting/InterceptingActivityFactory` which allows to intercept only one activity at a time. Child classes are responsible for creating activity object.

## Summary

| ### Public fields |
|---|---|
| `final https://developer.android.com/reference/java/lang/Class.html<T>` | `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#activityClassToIntercept()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#SingleActivityFactory(java.lang.Class<T>)(https://developer.android.com/reference/java/lang/Class.html<T> activityClassToIntercept)` |

| ### Public methods |
|---|---|
| `final https://developer.android.com/reference/android/app/Activity.html` | `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#create(java.lang.ClassLoader,java.lang.String,android.content.Intent)(https://developer.android.com/reference/java/lang/ClassLoader.html classLoader, https://developer.android.com/reference/java/lang/String.html className, https://developer.android.com/reference/android/content/Intent.html intent)` This method can be used to provide activity instance while intercepting activity creation for a particular activity in response to a given intent. |
| `final https://developer.android.com/reference/java/lang/Class.html<T>` | `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#getActivityClassToIntercept()()` This method can be used to get the Class of activity being instantiated by this factory. |
| `final boolean` | `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#shouldIntercept(java.lang.ClassLoader,java.lang.String,android.content.Intent)( https://developer.android.com/reference/java/lang/ClassLoader.html classLoader, https://developer.android.com/reference/java/lang/String.html className, https://developer.android.com/reference/android/content/Intent.html intent )` This method can be used to know whether activity instance creation should be intercepted or not for a particular activity in response to a given intent. |

| ### Protected methods |
|---|---|
| `abstract T` | `https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory#create(android.content.Intent)(https://developer.android.com/reference/android/content/Intent.html intent)` This method needs to be implemented by child class to create activity object for the given intent that specified the activity class being instantiated. |

## Public fields

### activityClassToIntercept

```
public final Class<T> activityClassToIntercept
```

## Public constructors

### SingleActivityFactory

```
public SingleActivityFactory(Class<T> activityClassToIntercept)
```

## Public methods

### create

```
public final Activity create(ClassLoader classLoader, String className, Intent intent)
```

This method can be used to provide activity instance while intercepting activity creation for a particular activity in response to a given intent.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/ClassLoader.html classLoader` | The ClassLoader with which to instantiate the object |
| `https://developer.android.com/reference/java/lang/String.html className` | The name of the class implementing the Activity object |
| `https://developer.android.com/reference/android/content/Intent.html intent` | The Intent object that specified the activity class being instantiated. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/app/Activity.html` | The newly instantiated Activity object. |

### getActivityClassToIntercept

```
public final Class<T> getActivityClassToIntercept()
```

This method can be used to get the Class of activity being instantiated by this factory.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Class.html<T>` | Class of the activity object being instantiated |

### shouldIntercept

```
public final boolean shouldIntercept(
    ClassLoader classLoader,
    String className,
    Intent intent
)
```

This method can be used to know whether activity instance creation should be intercepted or not for a particular activity in response to a given intent.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/ClassLoader.html classLoader` | The ClassLoader with which to instantiate the object |
| `https://developer.android.com/reference/java/lang/String.html className` | The name of the class implementing the Activity object |
| `https://developer.android.com/reference/android/content/Intent.html intent` | The Intent object that specified the activity class being instantiated. |

| Returns |
|---|---|
| `boolean` | true if activity with className should be intercepted, otherwise false. |

## Protected methods

### create

```
protected abstract T create(Intent intent)
```

This method needs to be implemented by child class to create activity object for the given intent that specified the activity class being instantiated.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html intent` | The Intent object that specified the activity class being instantiated. |

| Returns |
|---|---|
| `T` | The newly instantiated Activity object. |