public interface

DefaultLifecycleObserver

implements androidx.lifecycle.FullLifecycleObserver

 androidx.lifecycle.DefaultLifecycleObserver

Gradle dependencies

compile group: 'androidx.lifecycle', name: 'lifecycle-common', version: '2.5.0-rc01'

  • groupId: androidx.lifecycle
  • artifactId: lifecycle-common
  • version: 2.5.0-rc01

Artifact androidx.lifecycle:lifecycle-common:2.5.0-rc01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.lifecycle:lifecycle-common android.arch.lifecycle:common

Androidx class mapping:

androidx.lifecycle.DefaultLifecycleObserver android.arch.lifecycle.DefaultLifecycleObserver

Overview

Callback interface for listening to LifecycleOwner state changes. If a class implements both this interface and LifecycleEventObserver, then methods of DefaultLifecycleObserver will be called first, and then followed by the call of LifecycleEventObserver.onStateChanged(LifecycleOwner, Lifecycle.Event)

If a class implements this interface and in the same time uses OnLifecycleEvent, then annotations will be ignored.

Summary

Methods
public voidonCreate(LifecycleOwner owner)

Notifies that ON_CREATE event occurred.

public voidonDestroy(LifecycleOwner owner)

Notifies that ON_DESTROY event occurred.

public voidonPause(LifecycleOwner owner)

Notifies that ON_PAUSE event occurred.

public voidonResume(LifecycleOwner owner)

Notifies that ON_RESUME event occurred.

public voidonStart(LifecycleOwner owner)

Notifies that ON_START event occurred.

public voidonStop(LifecycleOwner owner)

Notifies that ON_STOP event occurred.

Methods

public void onCreate(LifecycleOwner owner)

Notifies that ON_CREATE event occurred.

This method will be called after the LifecycleOwner's onCreate method returns.

Parameters:

owner: the component, whose state was changed

public void onStart(LifecycleOwner owner)

Notifies that ON_START event occurred.

This method will be called after the LifecycleOwner's onStart method returns.

Parameters:

owner: the component, whose state was changed

public void onResume(LifecycleOwner owner)

Notifies that ON_RESUME event occurred.

This method will be called after the LifecycleOwner's onResume method returns.

Parameters:

owner: the component, whose state was changed

public void onPause(LifecycleOwner owner)

Notifies that ON_PAUSE event occurred.

This method will be called before the LifecycleOwner's onPause method is called.

Parameters:

owner: the component, whose state was changed

public void onStop(LifecycleOwner owner)

Notifies that ON_STOP event occurred.

This method will be called before the LifecycleOwner's onStop method is called.

Parameters:

owner: the component, whose state was changed

public void onDestroy(LifecycleOwner owner)

Notifies that ON_DESTROY event occurred.

This method will be called before the LifecycleOwner's onDestroy method is called.

Parameters:

owner: the component, whose state was changed

Source

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

import androidx.annotation.NonNull;

/**
 * Callback interface for listening to {@link LifecycleOwner} state changes.
 * If a class implements both this interface and {@link LifecycleEventObserver}, then
 * methods of {@code DefaultLifecycleObserver} will be called first, and then followed by the call
 * of {@link LifecycleEventObserver#onStateChanged(LifecycleOwner, Lifecycle.Event)}
 * <p>
 * If a class implements this interface and in the same time uses {@link OnLifecycleEvent}, then
 * annotations will be ignored.
 */
@SuppressWarnings("unused")
public interface DefaultLifecycleObserver extends FullLifecycleObserver {

    /**
     * Notifies that {@code ON_CREATE} event occurred.
     * <p>
     * This method will be called after the {@link LifecycleOwner}'s {@code onCreate}
     * method returns.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onCreate(@NonNull LifecycleOwner owner) {
    }

    /**
     * Notifies that {@code ON_START} event occurred.
     * <p>
     * This method will be called after the {@link LifecycleOwner}'s {@code onStart} method returns.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onStart(@NonNull LifecycleOwner owner) {
    }

    /**
     * Notifies that {@code ON_RESUME} event occurred.
     * <p>
     * This method will be called after the {@link LifecycleOwner}'s {@code onResume}
     * method returns.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onResume(@NonNull LifecycleOwner owner) {
    }

    /**
     * Notifies that {@code ON_PAUSE} event occurred.
     * <p>
     * This method will be called before the {@link LifecycleOwner}'s {@code onPause} method
     * is called.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onPause(@NonNull LifecycleOwner owner) {
    }

    /**
     * Notifies that {@code ON_STOP} event occurred.
     * <p>
     * This method will be called before the {@link LifecycleOwner}'s {@code onStop} method
     * is called.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onStop(@NonNull LifecycleOwner owner) {
    }

    /**
     * Notifies that {@code ON_DESTROY} event occurred.
     * <p>
     * This method will be called before the {@link LifecycleOwner}'s {@code onDestroy} method
     * is called.
     *
     * @param owner the component, whose state was changed
     */
    @Override
    default void onDestroy(@NonNull LifecycleOwner owner) {
    }
}