AppComponentFactory


public class AppComponentFactory
extends Object

java.lang.Object
   ↳ android.app.AppComponentFactory


Interface used to control the instantiation of manifest elements.

Summary

Public constructors

AppComponentFactory()

Public methods

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

Allows application to override the creation of activities.

Application instantiateApplication(ClassLoader cl, String className)

Allows application to override the creation of the application object.

ClassLoader instantiateClassLoader(ClassLoader cl, ApplicationInfo aInfo)

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

ContentProvider instantiateProvider(ClassLoader cl, String className)

Allows application to override the creation of providers.

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

Allows application to override the creation of receivers.

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

Allows application to override the creation of services.

Inherited methods

Public constructors

AppComponentFactory

public AppComponentFactory ()

Public methods

instantiateActivity

Added in API level 28
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.

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.

Returns
Activity This value cannot be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException

instantiateApplication

Added in API level 28
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.

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.

Returns
Application This value cannot be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException

instantiateClassLoader

Added in API level 29
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 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.

Returns
ClassLoader This value cannot be null.

instantiateProvider

Added in API level 28
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.

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.

Returns
ContentProvider This value cannot be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException

instantiateReceiver

Added in API level 28
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.

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.

Returns
BroadcastReceiver This value cannot be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException

instantiateService

Added in API level 28
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.

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.

Returns
Service This value cannot be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException