# SingleActivityFactory

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

*** ** * ** ***

Kotlin \|[Java](https://developer.android.com/reference/androidx/test/runner/intercepting/SingleActivityFactory "View this page in Java")


```
abstract class SingleActivityFactory<T : Activity?> : InterceptingActivityFactory
```

<br />

*** ** * ** ***

Abstract implementation of [InterceptingActivityFactory](https://developer.android.com/reference/kotlin/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 constructors                                                                                                                               |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SingleActivityFactory](https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/SingleActivityFactory#SingleActivityFactory(java.lang.Class<T>))`(activityClassToIntercept: `[Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>!)` |

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity.html)`!`    | [create](https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/SingleActivityFactory#create(java.lang.ClassLoader,java.lang.String,android.content.Intent))`(classLoader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`!, className: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!, intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!)` This method can be used to provide activity instance while intercepting activity creation for a particular activity in response to a given intent.                                      |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [shouldIntercept](https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/SingleActivityFactory#shouldIntercept(java.lang.ClassLoader,java.lang.String,android.content.Intent))`(` ` classLoader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`!,` ` className: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!` `)` 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 functions |
|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract T!`           | [create](https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/SingleActivityFactory#create(android.content.Intent))`(intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!)` 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 properties                             |
|------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Class](https://developer.android.com/reference/java/lang/Class.html)`<T!>!` | [activityClassToIntercept](https://developer.android.com/reference/kotlin/androidx/test/runner/intercepting/SingleActivityFactory#activityClassToIntercept()) |

## Public constructors

### SingleActivityFactory

```
SingleActivityFactory(activityClassToIntercept: Class<T!>!)
```  

## Public functions

### create

```
fun create(classLoader: ClassLoader!, className: String!, intent: Intent!): Activity!
```

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

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| `classLoader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`!` | The ClassLoader with which to instantiate the object                    |
| `className: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`   | The name of the class implementing the Activity object                  |
| `intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!`          | The Intent object that specified the activity class being instantiated. |

|                                     Returns                                      |
|----------------------------------------------------------------------------------|-----------------------------------------|
| [Activity](https://developer.android.com/reference/android/app/Activity.html)`!` | The newly instantiated Activity object. |

### shouldIntercept

```
fun shouldIntercept(
    classLoader: ClassLoader!,
    className: String!,
    intent: Intent!
): Boolean
```

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                                              |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| `classLoader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`!` | The ClassLoader with which to instantiate the object                    |
| `className: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`   | The name of the class implementing the Activity object                  |
| `intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!`          | The Intent object that specified the activity class being instantiated. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if activity with className should be intercepted, otherwise false. |

## Protected functions

### create

```
protected abstract fun create(intent: Intent!): T!
```

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                                         |
|--------------------------------------------------------------------------------------------|-------------------------------------------------------------------------|
| `intent: `[Intent](https://developer.android.com/reference/android/content/Intent.html)`!` | The Intent object that specified the activity class being instantiated. |

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

## Public properties

### activityClassToIntercept

```
val activityClassToIntercept: Class<T!>!
```