public class

CoreComponentFactory

extends AppComponentFactory

 java.lang.Object

↳android.app.AppComponentFactory

androidx.core.app.AppComponentFactory

↳androidx.core.app.CoreComponentFactory

Gradle dependencies

compile group: 'androidx.core', name: 'core', version: '1.15.0-alpha02'

  • groupId: androidx.core
  • artifactId: core
  • version: 1.15.0-alpha02

Artifact androidx.core:core:1.15.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.core:core com.android.support:support-compat

Androidx class mapping:

androidx.core.app.CoreComponentFactory android.support.v4.app.CoreComponentFactory

Overview

Instance of AppComponentFactory for support libraries.

Summary

Constructors
publicCoreComponentFactory()

Methods
public final ActivityinstantiateActivity(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

public final ApplicationinstantiateApplication(java.lang.ClassLoader cl, java.lang.String className)

public final ContentProviderinstantiateProvider(java.lang.ClassLoader cl, java.lang.String className)

public final BroadcastReceiverinstantiateReceiver(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

public final ServiceinstantiateService(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

from AppComponentFactoryinstantiateActivityCompat, instantiateApplicationCompat, instantiateProviderCompat, instantiateReceiverCompat, instantiateServiceCompat
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public CoreComponentFactory()

Methods

public final Activity instantiateActivity(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

See also: AppComponentFactory.instantiateActivityCompat(ClassLoader, String, Intent)

public final Application instantiateApplication(java.lang.ClassLoader cl, java.lang.String className)

See also: AppComponentFactory.instantiateApplicationCompat(ClassLoader, String)

public final BroadcastReceiver instantiateReceiver(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

See also: AppComponentFactory.instantiateReceiverCompat(ClassLoader, String, Intent)

public final ContentProvider instantiateProvider(java.lang.ClassLoader cl, java.lang.String className)

See also: AppComponentFactory.instantiateProviderCompat(ClassLoader, String)

public final Service instantiateService(java.lang.ClassLoader cl, java.lang.String className, Intent intent)

See also: AppComponentFactory.instantiateServiceCompat(ClassLoader, String, Intent)

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.core.app;

import android.app.Activity;
import android.app.AppComponentFactory;
import android.app.Application;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ContentProvider;
import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

/**
 * Instance of AppComponentFactory for support libraries.
 * @see CompatWrapped
 */
@RequiresApi(api = 28)
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
public class CoreComponentFactory extends AppComponentFactory {
    @NonNull
    @Override
    public Activity instantiateActivity(
            @NonNull ClassLoader cl, @NonNull String className, @Nullable Intent intent)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return checkCompatWrapper(super.instantiateActivity(cl, className, intent));
    }

    @NonNull
    @Override
    public Application instantiateApplication(@NonNull ClassLoader cl, @NonNull String className)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return checkCompatWrapper(super.instantiateApplication(cl, className));
    }

    @NonNull
    @Override
    public BroadcastReceiver instantiateReceiver(@NonNull ClassLoader cl, @NonNull String className,
            @Nullable Intent intent)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return checkCompatWrapper(super.instantiateReceiver(cl, className, intent));
    }

    @NonNull
    @Override
    public ContentProvider instantiateProvider(@NonNull ClassLoader cl, @NonNull String className)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return checkCompatWrapper(super.instantiateProvider(cl, className));
    }

    @NonNull
    @Override
    public Service instantiateService(
            @NonNull ClassLoader cl, @NonNull String className, @Nullable Intent intent)
            throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        return checkCompatWrapper(super.instantiateService(cl, className, intent));
    }

    @SuppressWarnings("unchecked")
    static <T> T checkCompatWrapper(T obj) {
        if (obj instanceof CompatWrapped) {
            T wrapper = (T) ((CompatWrapped) obj).getWrapper();
            if (wrapper != null) {
                return wrapper;
            }
        }
        return obj;
    }

    /**
     * Implement this interface to allow a different class to be returned when instantiating
     * on certain API levels.
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
    public interface CompatWrapped {
        /**
         * Called while this class is being instantiated by the OS.
         *
         * If an object is returned then it will be used in place of the class.
         * Note: this will not be called on API <= 27.
         *
         * Example:
         * <pre class="prettyprint">
         * {@literal
         * public AndroidXContentProvider extends ContentProvider implements CompatWrapped {
         *     ...
         *
         *     public Object getWrapper() {
         *         if (SDK_INT >= 29) {
         *             return new AndroidXContentProviderV29(this);
         *         }
         *         return null;
         *     }
         * }
         * }
         * </pre>
         */
        Object getWrapper();
    }

}