AppComponentFactory.InstantiateService(ClassLoader, String, Intent) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Allows application to override the creation of services.
[Android.Runtime.Register("instantiateService", "(Ljava/lang/ClassLoader;Ljava/lang/String;Landroid/content/Intent;)Landroid/app/Service;", "GetInstantiateService_Ljava_lang_ClassLoader_Ljava_lang_String_Landroid_content_Intent_Handler", ApiSince=28)]
public virtual Android.App.Service InstantiateService(Java.Lang.ClassLoader cl, string className, Android.Content.Intent? intent);
[<Android.Runtime.Register("instantiateService", "(Ljava/lang/ClassLoader;Ljava/lang/String;Landroid/content/Intent;)Landroid/app/Service;", "GetInstantiateService_Ljava_lang_ClassLoader_Ljava_lang_String_Landroid_content_Intent_Handler", ApiSince=28)>]
abstract member InstantiateService : Java.Lang.ClassLoader * string * Android.Content.Intent -> Android.App.Service
override this.InstantiateService : Java.Lang.ClassLoader * string * Android.Content.Intent -> Android.App.Service
Parameters
- cl
- ClassLoader
ClassLoader: The default classloader to use for instantiation. This value cannot be null.
- className
- String
String: The class to be instantiated. This value cannot be null.
- intent
- Intent
Intent: Intent creating the class. This value may be null.
Returns
This value cannot be null.
- Attributes
Remarks
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.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2026-08-03 UTC.
Throws: ClassNotFoundException
Throws: IllegalAccessException
Throws: InstantiationException
Android reference for android.app.AppComponentFactory.instantiateService.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.