Added in API level 28

AppComponentFactory

open class AppComponentFactory
kotlin.Any
   ↳ android.app.AppComponentFactory

Interface used to control the instantiation of manifest elements.

Summary

Public constructors

Public methods
open Activity
instantiateActivity(cl: ClassLoader, className: String, intent: Intent?)

Allows application to override the creation of activities.

open Application

Allows application to override the creation of the application object.

open ClassLoader

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

open ContentProvider

Allows application to override the creation of providers.

open BroadcastReceiver
instantiateReceiver(cl: ClassLoader, className: String, intent: Intent?)

Allows application to override the creation of receivers.

open Service
instantiateService(cl: ClassLoader, className: String, intent: Intent?)

Allows application to override the creation of services.

Public constructors

AppComponentFactory

AppComponentFactory()

Public methods

instantiateActivity

Added in API level 28
open fun instantiateActivity(
    cl: ClassLoader,
    className: String,
    intent: Intent?
): Activity

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.

Parameters
cl ClassLoader: The default classloader to use for instantiation. This value cannot be null.
className String: The class to be instantiated. This value cannot be null.
intent Intent?: Intent creating the class. This value may be null.
Return
Activity This value cannot be null.

instantiateApplication

Added in API level 28
open fun instantiateApplication(
    cl: ClassLoader,
    className: String
): Application

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.

Parameters
cl ClassLoader: The default classloader to use for instantiation. This value cannot be null.
className String: The class to be instantiated. This value cannot be null.
Return
Application This value cannot be null.

instantiateClassLoader

Added in API level 29
open fun instantiateClassLoader(
    cl: ClassLoader,
    aInfo: ApplicationInfo
): ClassLoader

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 android.R.attr#classLoader manifest attribute.

Parameters
cl ClassLoader: The default class loader created by the platform. This value cannot be null.
aInfo ApplicationInfo: Information about the application being loaded. This value cannot be null.
Return
ClassLoader This value cannot be null.

instantiateProvider

Added in API level 28
open fun instantiateProvider(
    cl: ClassLoader,
    className: String
): ContentProvider

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.

Parameters
cl ClassLoader: The default classloader to use for instantiation. This value cannot be null.
className String: The class to be instantiated. This value cannot be null.
Return
ContentProvider This value cannot be null.

instantiateReceiver

Added in API level 28
open fun instantiateReceiver(
    cl: ClassLoader,
    className: String,
    intent: Intent?
): BroadcastReceiver

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.

Parameters
cl ClassLoader: The default classloader to use for instantiation. This value cannot be null.
className String: The class to be instantiated. This value cannot be null.
intent Intent?: Intent creating the class. This value may be null.
Return
BroadcastReceiver This value cannot be null.

instantiateService

Added in API level 28
open fun instantiateService(
    cl: ClassLoader,
    className: String,
    intent: Intent?
): Service

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.

Parameters
cl ClassLoader: The default classloader to use for instantiation. This value cannot be null.
className String: The class to be instantiated. This value cannot be null.
intent Intent?: Intent creating the class. This value may be null.
Return
Service This value cannot be null.