Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

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)

Allows application to override the creation of the default class loader.

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 must never be null.

className String: The class to be instantiated. This value must never be null.

intent Intent: Intent creating the class. This value may be null.

Returns
Activity This value will never 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 must never be null.

className String: The class to be instantiated. This value must never be null.

Returns
Application This value will never be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException

instantiateClassLoader

public ClassLoader instantiateClassLoader (ClassLoader cl, 
                ApplicationInfo aInfo)

Allows application to override the creation of the default class loader. This can be used to perform things such as dependency injection or setting up a custom class loader hierarchy.

Parameters
cl ClassLoader: The default classloader instantiated by platform. This value must never be null.

aInfo ApplicationInfo: Information about the application being loaded. This value must never be null.

Returns
ClassLoader This value will never 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 must never be null.

className String: The class to be instantiated. This value must never be null.

Returns
ContentProvider This value will never 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 must never be null.

className String: The class to be instantiated. This value must never be null.

intent Intent: Intent creating the class. This value may be null.

Returns
BroadcastReceiver This value will never 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 must never be null.

className String: The class to be instantiated. This value must never be null.

intent Intent: Intent creating the class. This value may be null.

Returns
Service This value will never be null.

Throws
ClassNotFoundException
IllegalAccessException
InstantiationException