# AppComponentFactory

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/app/AppComponentFactory#pubctors)\|[Methods](https://developer.android.com/reference/android/app/AppComponentFactory#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/AppComponentFactory#inhmethods)  

# AppComponentFactory

*** ** * ** ***

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

`
public


class
AppComponentFactory
`  
`

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


``


`

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

<br />

*** ** * ** ***

Interface used to control the instantiation of manifest elements.  
**See also:**

- [instantiateApplication(ClassLoader, String)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateApplication(java.lang.ClassLoader,%20java.lang.String))
- [instantiateActivity(ClassLoader, String, Intent)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateActivity(java.lang.ClassLoader,%20java.lang.String,%20android.content.Intent))
- [instantiateClassLoader(ClassLoader, ApplicationInfo)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateClassLoader(java.lang.ClassLoader,%20android.content.pm.ApplicationInfo))
- [instantiateService(ClassLoader, String, Intent)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateService(java.lang.ClassLoader,%20java.lang.String,%20android.content.Intent))
- [instantiateReceiver(ClassLoader, String, Intent)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateReceiver(java.lang.ClassLoader,%20java.lang.String,%20android.content.Intent))
- [instantiateProvider(ClassLoader, String)](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateProvider(java.lang.ClassLoader,%20java.lang.String))

## Summary

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

|                                                                                                                                                                                                                                                                                                ### Public methods                                                                                                                                                                                                                                                                                                 ||
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[Activity](https://developer.android.com/reference/android/app/Activity)                       | ` `[instantiateActivity](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateActivity(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) ` Allows application to override the creation of activities. |
| ` `[Application](https://developer.android.com/reference/android/app/Application)                 | ` `[instantiateApplication](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateApplication(java.lang.ClassLoader,%20java.lang.String))`(`[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)` cl, `[String](https://developer.android.com/reference/java/lang/String)` className) ` Allows application to override the creation of the application object.                                                                                            |
| ` `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)                   | ` `[instantiateClassLoader](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateClassLoader(java.lang.ClassLoader,%20android.content.pm.ApplicationInfo))`(`[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)` cl, `[ApplicationInfo](https://developer.android.com/reference/android/content/pm/ApplicationInfo)` aInfo) ` Selects the class loader which will be used by the platform to instantiate app components.                               |
| ` `[ContentProvider](https://developer.android.com/reference/android/content/ContentProvider)     | ` `[instantiateProvider](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateProvider(java.lang.ClassLoader,%20java.lang.String))`(`[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader)` cl, `[String](https://developer.android.com/reference/java/lang/String)` className) ` Allows application to override the creation of providers.                                                                                                               |
| ` `[BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver) | ` `[instantiateReceiver](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateReceiver(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) ` Allows application to override the creation of receivers.  |
| ` `[Service](https://developer.android.com/reference/android/app/Service)                         | ` `[instantiateService](https://developer.android.com/reference/android/app/AppComponentFactory#instantiateService(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) ` Allows application to override the creation of services.     |

| ### 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*.                                                                                             | ||

## Public constructors

### AppComponentFactory

```
public AppComponentFactory ()
```

<br />

<br />

## Public methods

### instantiateActivity

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

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

Allows application to override the creation of activities. This can be used to perform things such as dependency injection or class loader changes to these classes.

This method is only intended to provide a hook for instantiation. It does not provide earlier access to the Activity object. The returned object will not be initialized as a Context yet and should not be used to interact with other android APIs.

<br />

|                                                    Parameters                                                    ||
|-------------|-----------------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The default classloader to use for instantiation. This value cannot be`null`. <br /> |
| `className` | `String`: The class to be instantiated. This value cannot be`null`. <br />                          |
| `intent`    | `Intent`: Intent creating the class. This value may be`null`. <br />                                |

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

### instantiateApplication

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

```
public Application instantiateApplication (ClassLoader cl, 
                String className)
```

Allows application to override the creation of the application object. This can be used to perform things such as dependency injection or class loader changes to these classes.

This method is only intended to provide a hook for instantiation. It does not provide earlier access to the Application object. The returned object will not be initialized as a Context yet and should not be used to interact with other android APIs.

<br />

|                                                    Parameters                                                    ||
|-------------|-----------------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The default classloader to use for instantiation. This value cannot be`null`. <br /> |
| `className` | `String`: The class to be instantiated. This value cannot be`null`. <br />                          |

|                                                      Returns                                                       ||
|--------------------------------------------------------------------------------|------------------------------------|
| [Application](https://developer.android.com/reference/android/app/Application) | This value cannot be`null`. <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) |   |

### instantiateClassLoader

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

```
public ClassLoader instantiateClassLoader (ClassLoader cl, 
                ApplicationInfo aInfo)
```

Selects the class loader which will be used by the platform to instantiate app components.

The default implementation of this method returns the`cl`parameter unchanged. Applications can override this method to set up a custom class loader or a custom class loader hierarchy and return it to the platform.

The method is a hook invoked before any application components are instantiated or the application Context is initialized. It is intended to allow the application's classes to be loaded from a different source than the base/split APK(s).

The default class loader`cl`is created by the platform and used to load the application's base or split APK(s). Its parent is typically the boot class loader, unless running under instrumentation. Its classname is configurable using the[R.attr.classLoader](https://developer.android.com/reference/android/R.attr#classLoader)manifest attribute.

<br />

|                                                   Parameters                                                   ||
|---------|-------------------------------------------------------------------------------------------------------|
| `cl`    | `ClassLoader`: The default class loader created by the platform. This value cannot be`null`. <br />   |
| `aInfo` | `ApplicationInfo`: Information about the application being loaded. This value cannot be`null`. <br /> |

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

### instantiateProvider

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

```
public ContentProvider instantiateProvider (ClassLoader cl, 
                String className)
```

Allows application to override the creation of providers. This can be used to perform things such as dependency injection or class loader changes to these classes.

This method is only intended to provide a hook for instantiation. It does not provide earlier access to the ContentProvider object. The returned object will not be initialized with a Context yet and should not be used to interact with other android APIs.

<br />

|                                                    Parameters                                                    ||
|-------------|-----------------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The default classloader to use for instantiation. This value cannot be`null`. <br /> |
| `className` | `String`: The class to be instantiated. This value cannot be`null`. <br />                          |

|                                                            Returns                                                             ||
|--------------------------------------------------------------------------------------------|------------------------------------|
| [ContentProvider](https://developer.android.com/reference/android/content/ContentProvider) | This value cannot be`null`. <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) |   |

### instantiateReceiver

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

```
public BroadcastReceiver instantiateReceiver (ClassLoader cl, 
                String className, 
                Intent intent)
```

Allows application to override the creation of receivers. This can be used to perform things such as dependency injection or class loader changes to these classes.

<br />

|                                                    Parameters                                                    ||
|-------------|-----------------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The default classloader to use for instantiation. This value cannot be`null`. <br /> |
| `className` | `String`: The class to be instantiated. This value cannot be`null`. <br />                          |
| `intent`    | `Intent`: Intent creating the class. This value may be`null`. <br />                                |

|                                                              Returns                                                               ||
|------------------------------------------------------------------------------------------------|------------------------------------|
| [BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver) | This value cannot be`null`. <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) |   |

### instantiateService

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

```
public Service instantiateService (ClassLoader cl, 
                String className, 
                Intent intent)
```

Allows application to override the creation of services. This can be used to perform things such as dependency injection or class loader changes to these classes.

This method is only intended to provide a hook for instantiation. It does not provide earlier access to the Service object. The returned object will not be initialized as a Context yet and should not be used to interact with other android APIs.

<br />

|                                                    Parameters                                                    ||
|-------------|-----------------------------------------------------------------------------------------------------|
| `cl`        | `ClassLoader`: The default classloader to use for instantiation. This value cannot be`null`. <br /> |
| `className` | `String`: The class to be instantiated. This value cannot be`null`. <br />                          |
| `intent`    | `Intent`: Intent creating the class. This value may be`null`. <br />                                |

|                                                  Returns                                                   ||
|------------------------------------------------------------------------|------------------------------------|
| [Service](https://developer.android.com/reference/android/app/Service) | This value cannot be`null`. <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) |   |