public interface

Initializer<T>

 androidx.startup.Initializer<T>

Subclasses:

EmojiCompatInitializer, WorkManagerInitializer, ProfileInstallerInitializer, ProcessLifecycleInitializer

Gradle dependencies

compile group: 'androidx.startup', name: 'startup-runtime', version: '1.2.0-alpha01'

  • groupId: androidx.startup
  • artifactId: startup-runtime
  • version: 1.2.0-alpha01

Artifact androidx.startup:startup-runtime:1.2.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Initializers can be used to initialize libraries during app startup, without the need to use additional s.

Summary

Methods
public java.lang.Objectcreate(Context context)

Initializes and a component given the application

public java.util.List<java.lang.Class>dependencies()

Methods

public java.lang.Object create(Context context)

Initializes and a component given the application

Parameters:

context: The application context.

public java.util.List<java.lang.Class> dependencies()

Returns:

A list of dependencies that this Initializer depends on. This is used to determine initialization order of Initializers.
For e.g. if a Initializer `B` defines another Initializer `A` as its dependency, then `A` gets initialized before `B`.

Source

/*
 * Copyright 2020 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.startup;

import android.content.Context;

import androidx.annotation.NonNull;

import java.util.List;

/**
 * {@link Initializer}s can be used to initialize libraries during app startup, without
 * the need to use additional {@link android.content.ContentProvider}s.
 *
 * @param <T> The instance type being initialized
 */
public interface Initializer<T> {

    /**
     * Initializes and a component given the application {@link Context}
     *
     * @param context The application context.
     */
    @NonNull
    T create(@NonNull Context context);

    /**
     * @return A list of dependencies that this {@link Initializer} depends on. This is
     * used to determine initialization order of {@link Initializer}s.
     * <br/>
     * For e.g. if a {@link Initializer} `B` defines another
     * {@link Initializer} `A` as its dependency, then `A` gets initialized before `B`.
     */
    @NonNull
    List<Class<? extends Initializer<?>>> dependencies();
}