public interface

Manager

 androidx.car.app.managers.Manager

Subclasses:

SuggestionManager, ScreenManager, AppManager, TestScreenManager, TestAppManager, TestNavigationManager, ConstraintManager, ResultManagerAutomotive, ResultManager, CarHardwareManager, ProjectedCarHardwareManager, AutomotiveCarHardwareManager, MediaPlaybackManager, NavigationManager

Gradle dependencies

compile group: 'androidx.car.app', name: 'app', version: '1.7.0-beta01'

  • groupId: androidx.car.app
  • artifactId: app
  • version: 1.7.0-beta01

Artifact androidx.car.app:app:1.7.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

A manager that extends the services provided by CarContext. These manager can be obtained from CarContext.getCarService(Class) or CarContext.getCarService(String)

Summary

Methods
public static Managercreate(java.lang.Class<Manager> clazz, java.lang.String className, java.lang.Object args[])

Helper method to create managers by reflection

Methods

public static Manager create(java.lang.Class<Manager> clazz, java.lang.String className, java.lang.Object args[])

Helper method to create managers by reflection

Parameters:

clazz: interface manager expected to receive
className: class name of the manager
args: arguments to send to the manager

Returns:

an instance of the given manager, or null if the given class name is not found.

Source

/*
 * Copyright 2021 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.car.app.managers;

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

import java.lang.reflect.Constructor;

/**
 * A manager that extends the services provided by {@link androidx.car.app.CarContext}. These
 * manager can be obtained from {@link androidx.car.app.CarContext#getCarService(Class)} or
 * {@link androidx.car.app.CarContext#getCarService(String)}
 */
public interface Manager {
    /**
     * Helper method to create managers by reflection
     *
     * @param clazz interface manager expected to receive
     * @param className class name of the manager
     * @param args arguments to send to the manager
     * @param <U> manager type
     * @return an instance of the given manager, or null if the given class name is not found.
     * @throws IllegalStateException if the class exists, but there was an error trying to
     *         instantiate it.
     *
     */
    @RestrictTo(RestrictTo.Scope.LIBRARY)
    @Nullable
    static <U extends Manager> U create(@NonNull Class<U> clazz, @NonNull String className,
            @NonNull Object ... args) {
        try { // Check for automotive library first.
            Class<?> c = Class.forName(className);
            Class<?>[] argsTypes = new Class<?>[args.length];
            for (int i = 0; i < args.length; i++) {
                argsTypes[i] = args[i].getClass();
            }
            Constructor<?> ctor = c.getConstructor(argsTypes);
            return clazz.cast(ctor.newInstance(args));
        } catch (ClassNotFoundException e) {
            // Not found, fall through.
            return null;
        } catch (ReflectiveOperationException e) {
            // Something went wrong with accessing the constructor or calling newInstance().
            throw new IllegalStateException("Mismatch with artifact", e);
        }
    }
}