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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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传参加以区分:

1
2
3
4
5
public enum IntentFlag {
NONE,
ACTIVITY_SINGLE,
ACTIVITY_VIEW_GROUP
}

例如登录跳转:

1
2
3
4
5
6
7
8
9
10
11
12
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();

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :