public interface

FragmentOnAttachListener

 androidx.fragment.app.FragmentOnAttachListener

Gradle dependencies

compile group: 'androidx.fragment', name: 'fragment', version: '1.5.0-rc01'

  • groupId: androidx.fragment
  • artifactId: fragment
  • version: 1.5.0-rc01

Artifact androidx.fragment:fragment:1.5.0-rc01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.fragment:fragment com.android.support:support-fragment

Overview

Listener for receiving a callback immediately following Fragment.onAttach(Context). This can be used to perform any additional setup / provide any dependencies that the Fragment may need prior to child fragments being attached or the Fragment going through Fragment.onCreate(Bundle).

Summary

Methods
public voidonAttachFragment(FragmentManager fragmentManager, Fragment fragment)

Called after the fragment has been attached to its host.

Methods

public void onAttachFragment(FragmentManager fragmentManager, Fragment fragment)

Called after the fragment has been attached to its host. This is called immediately after Fragment.onAttach(Context) and before Fragment.onAttach(Context) has been called on any child fragments.

Parameters:

fragmentManager: FragmentManager the fragment is now attached to. This will be the same FragmentManager that is returned by Fragment.getParentFragmentManager().
fragment: Fragment that just received a callback to Fragment.onAttach(Context)

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.fragment.app;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.MainThread;
import androidx.annotation.NonNull;

/**
 * Listener for receiving a callback immediately following {@link Fragment#onAttach(Context)}.
 * This can be used to perform any additional setup / provide any dependencies that the Fragment
 * may need prior to child fragments being attached or the Fragment going through
 * {@link Fragment#onCreate(Bundle)}.
 *
 * @see FragmentManager#addFragmentOnAttachListener(FragmentOnAttachListener)
 */
public interface FragmentOnAttachListener {
    /**
     * Called after the fragment has been attached to its host. This is called
     * immediately after {@link Fragment#onAttach(Context)} and before
     * {@link Fragment#onAttach(Context)} has been called on any child fragments.
     *
     * @param fragmentManager FragmentManager the fragment is now attached to. This will
     *                        be the same FragmentManager that is returned by
     *                        {@link Fragment#getParentFragmentManager()}.
     * @param fragment Fragment that just received a callback to {@link Fragment#onAttach(Context)}
     */
    @MainThread
    void onAttachFragment(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment);
}