Java Code Examples for androidx.fragment.app.FragmentManager#FragmentLifecycleCallbacks

The following examples show how to use androidx.fragment.app.FragmentManager#FragmentLifecycleCallbacks . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityLifecycle.java    From MVPArms with Apache License 2.0 5 votes vote down vote up
/**
 * 给每个 Activity 的所有 Fragment 设置监听其生命周期, Activity 可以通过 {@link IActivity#useFragment()}
 * 设置是否使用监听,如果这个 Activity 返回 false 的话,这个 Activity 下面的所有 Fragment 将不能使用 {@link FragmentDelegate}
 * 意味着 {@link BaseFragment} 也不能使用
 *
 * @param activity
 */
private void registerFragmentCallbacks(Activity activity) {

    boolean useFragment = !(activity instanceof IActivity) || ((IActivity) activity).useFragment();
    if (activity instanceof FragmentActivity && useFragment) {

        //mFragmentLifecycle 为 Fragment 生命周期实现类, 用于框架内部对每个 Fragment 的必要操作, 如给每个 Fragment 配置 FragmentDelegate
        //注册框架内部已实现的 Fragment 生命周期逻辑
        ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(mFragmentLifecycle.get(), true);

        if (mExtras.containsKey(IntelligentCache.getKeyOfKeep(ConfigModule.class.getName()))) {
            @SuppressWarnings("unchecked")
            List<ConfigModule> modules = (List<ConfigModule>) mExtras.get(IntelligentCache.getKeyOfKeep(ConfigModule.class.getName()));
            if (modules != null) {
                for (ConfigModule module : modules) {
                    module.injectFragmentLifecycle(mApplication, mFragmentLifecycles.get());
                }
            }
            mExtras.remove(IntelligentCache.getKeyOfKeep(ConfigModule.class.getName()));
        }

        //注册框架外部, 开发者扩展的 Fragment 生命周期逻辑
        for (FragmentManager.FragmentLifecycleCallbacks fragmentLifecycle : mFragmentLifecycles.get()) {
            ((FragmentActivity) activity).getSupportFragmentManager().registerFragmentLifecycleCallbacks(fragmentLifecycle, true);
        }
    }
}
 
Example 2
Source File: ActivityControlImpl.java    From FastLib with Apache License 2.0 4 votes vote down vote up
/**
 * Fragment 生命周期回调
 *
 * @return
 */
@Override
public FragmentManager.FragmentLifecycleCallbacks getFragmentLifecycleCallbacks() {
    return new FragmentManager.FragmentLifecycleCallbacks() {
    };
}
 
Example 3
Source File: GlobalConfiguration.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Override
public void injectFragmentLifecycle(@NonNull Context context, @NonNull List<FragmentManager.FragmentLifecycleCallbacks> lifecycles) {
    //FragmentLifecycleCallbacks 中的所有方法都会在 Fragment (包括三方库) 的对应生命周期中被调用, 所以在对应的方法中可以扩展一些自己需要的逻辑
    //可以根据不同的逻辑添加多个实现类
    lifecycles.add(new FragmentLifecycleCallbacksImpl());
}
 
Example 4
Source File: AppModule.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Singleton
@Provides
static List<FragmentManager.FragmentLifecycleCallbacks> provideFragmentLifecycles() {
    return new ArrayList<>();
}
 
Example 5
Source File: AppModule.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Binds
abstract FragmentManager.FragmentLifecycleCallbacks bindFragmentLifecycle(FragmentLifecycle fragmentLifecycle);
 
Example 6
Source File: ActivityFragmentControl.java    From FastLib with Apache License 2.0 2 votes vote down vote up
/**
 * Fragment全局生命周期回调
 *
 * @return
 */
FragmentManager.FragmentLifecycleCallbacks getFragmentLifecycleCallbacks();
 
Example 7
Source File: ConfigModule.java    From MVPArms with Apache License 2.0 2 votes vote down vote up
/**
 * 使用 {@link FragmentManager.FragmentLifecycleCallbacks} 在 {@link Fragment} 的生命周期中注入一些操作
 *
 * @param context    {@link Context}
 * @param lifecycles {@link Fragment} 的生命周期容器, 可向框架中添加多个 {@link Fragment} 的生命周期类
 */
void injectFragmentLifecycle(@NonNull Context context, @NonNull List<FragmentManager.FragmentLifecycleCallbacks> lifecycles);