public interface

ApplicationLifecycleMonitor

 androidx.test.runner.lifecycle.ApplicationLifecycleMonitor

Subclasses:

ApplicationLifecycleMonitorImpl

Gradle dependencies

compile group: 'androidx.test', name: 'monitor', version: '1.6.0-alpha03'

  • groupId: androidx.test
  • artifactId: monitor
  • version: 1.6.0-alpha03

Artifact androidx.test:monitor:1.6.0-alpha03 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test:monitor com.android.support.test:monitor

Androidx class mapping:

androidx.test.runner.lifecycle.ApplicationLifecycleMonitor android.support.test.runner.lifecycle.ApplicationLifecycleMonitor

Overview

Interface for tests to use when they need to be informed of the application lifecycle state.

Retrieve instances of the monitor thru ApplicationLifecycleMonitorRegistry.

Detecting these lifecycle states requires support from Instrumentation, therefore do not expect an instance to be present under any arbitrary instrumentation.

Summary

Methods
public voidaddLifecycleCallback(ApplicationLifecycleCallback callback)

Adds a new callback that will be notified when lifecycle changes occur.

public voidremoveLifecycleCallback(ApplicationLifecycleCallback callback)

Removes a previously registered lifecycle callback.

Methods

public void addLifecycleCallback(ApplicationLifecycleCallback callback)

Adds a new callback that will be notified when lifecycle changes occur.

Implementors will not hold a strong ref to the callback, the code which registers callbacks is responsible for this. Code which registers callbacks should responsibly remove their callback when it is no longer needed.

Callbacks may be executed on the main thread of the application, and should take care not to block or otherwise perform expensive operations as it will directly impact the application.

Parameters:

callback: an ApplicationLifecycleCallback

public void removeLifecycleCallback(ApplicationLifecycleCallback callback)

Removes a previously registered lifecycle callback.

Source

/*
 * Copyright (C) 2014 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.test.runner.lifecycle;

/**
 * Interface for tests to use when they need to be informed of the application lifecycle state.
 *
 * <p>Retrieve instances of the monitor thru ApplicationLifecycleMonitorRegistry.
 *
 * <p>Detecting these lifecycle states requires support from Instrumentation, therefore do not
 * expect an instance to be present under any arbitrary instrumentation.
 */
public interface ApplicationLifecycleMonitor {

  /**
   * Adds a new callback that will be notified when lifecycle changes occur.
   *
   * <p>Implementors will not hold a strong ref to the callback, the code which registers callbacks
   * is responsible for this. Code which registers callbacks should responsibly remove their
   * callback when it is no longer needed.
   *
   * <p>Callbacks may be executed on the main thread of the application, and should take care not to
   * block or otherwise perform expensive operations as it will directly impact the application.
   *
   * @param callback an ApplicationLifecycleCallback
   */
  void addLifecycleCallback(ApplicationLifecycleCallback callback);

  /** Removes a previously registered lifecycle callback. */
  void removeLifecycleCallback(ApplicationLifecycleCallback callback);
}