Atlas加载bundle插件总结:ViewGroup中加载及本地startActivity方式

Atlas在ViewGroup中及本地startActivity方式加载bundle插件

public class AtlasDelegateHelper {

    //ViewGroup中加载
    public static void switchToActivity(Activity activity, ActivityGroupDelegate delegate, ViewGroup container, String key, String activityName) {
        Intent intent = new Intent();
        intent.setClassName(activity.getBaseContext(), activityName);
        delegate.startChildActivity(container, key, intent);
    }

    //本地加载
    public static void startBundleActivity(Context context, String activityName) {
        Intent intent = new Intent();
        intent.setClassName(context, activityName);
        context.startActivity(intent);
    }

    public static void startBundleActivity(Activity activity, String activityName) {
        Intent intent = new Intent();
        intent.setClassName(activity, activityName);
        activity.startActivity(intent);
    }

    public static void startBundleActivity(Fragment fragment, String activityName) {
        Intent intent = new Intent();
        Context context = fragment.getContext();
        if (context != null) {
            intent.setClassName(fragment.getContext(), activityName);
        }
        fragment.startActivity(intent);
    }

    public static void startBundleActivities(Activity activity, String... activityNames) {
        if (activityNames != null && activityNames.length > 0) {
            Intent[] intents = new Intent[activityNames.length];
            for (int i = 0; i < activityNames.length; i++) {
                intents[i] = new Intent();
                intents[i].setClassName(activity, activityNames[i]);
            }
            activity.startActivities(intents);
        }
    }

    public static void startBundleActivity(Activity activity, String activityName, Bundle bundle) {
        Intent intent = new Intent();
        intent.putExtras(bundle);
        intent.setClassName(activity, activityName);
        activity.startActivity(intent);
    }

    public static void startBundleActivity(Fragment fragment, String activityName, Bundle bundle) {
        Intent intent = new Intent();
        intent.putExtras(bundle);
        Context context = fragment.getContext();
        if (context != null) {
            intent.setClassName(fragment.getContext(), activityName);
        }
        fragment.startActivity(intent);
    }

    public static void startBundleActivities(Activity activity, String[] activityNames, Bundle[] bundles) {
        if (activityNames != null && bundles != null && activityNames.length > 0 && bundles.length == activityNames.length) {
            Intent[] intents = new Intent[activityNames.length];
            for (int i = 0; i < activityNames.length; i++) {
                intents[i] = new Intent();
                intents[i].putExtras(bundles[i]);
                intents[i].setClassName(activity, activityNames[i]);
            }
            activity.startActivities(intents);
        }
    }

    public static void startBundleActivityForResult(Activity activity, String activityName, Bundle bundle, int requestCode) {
        Intent intent = new Intent();
        intent.putExtras(bundle);
        intent.setClassName(activity, activityName);
        activity.startActivityForResult(intent, requestCode);
    }

    public static void startBundleActivityForResult(Fragment fragment, String activityName, Bundle bundle, int requestCode) {
        Intent intent = new Intent();
        intent.putExtras(bundle);
        Context context = fragment.getContext();
        if (context != null) {
            intent.setClassName(context, activityName);
        }
        fragment.startActivityForResult(intent, requestCode);
    }

}

区分ViewGroup中加载与本地startActivity方式加载

可通过Intent传参加以区分:

public enum IntentFlag {
    NONE,
    ACTIVITY_SINGLE,
    ACTIVITY_VIEW_GROUP
}

例如登录跳转:

if (mPageClass != null) {
    if (mBundle == null) {
        mBundle = new Bundle();
    }
    mBundle.putInt("activity_flag", IntentFlag.ACTIVITY_SINGLE.ordinal());
    AtlasDelegateHelper.startBundleActivities(mActivity, new String[]{ActivityConfig.ACTIVITY_MAIN, mPageClass.getName()}, new Bundle[]{new Bundle(), mBundle});
    mActivity.overridePendingTransition(R.anim.push_bottom_in, R.anim.push_bottom_out);
} else {
    AtlasDelegateHelper.startBundleActivity(mActivity, ActivityConfig.ACTIVITY_MAIN);
    mActivity.overridePendingTransition(R.anim.push_bottom_in, R.anim.push_bottom_out);
}
mActivity.finish();

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/summary-of-atlas-loading-bundle-plugins-viewgroup-and-local-startactivity-loading-methods/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Atlas加载bundle插件总结:ViewGroup中加载及本地startActivity方式
Atlas在ViewGroup中及本地startActivity方式加载bundle插件 public class AtlasDelegateHelper { //ViewGroup中加载 public static void switchToAc……
<<上一篇
下一篇>>
文章目录
关闭
目 录