AppComponentFactory

Kotlin | Java

public class AppComponentFactory

extends Object

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 java.lang.Object From class Object clone() Creates and returns a copy of this object. boolean equals(Object obj) Indicates whether some other object is "equal to" this one. void finalize() Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. final Class<?> getClass() Returns the runtime class of this Object . int hashCode() Returns a hash code value for the object. final void notify() Wakes up a single thread that is waiting on this object's monitor. final void notifyAll() Wakes up all threads that are waiting on this object's monitor. String toString() Returns a string representation of the object. final void wait(long timeout, int nanos) Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed. final void wait(long timeout) Causes the current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. final void wait() Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

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