废话不说,直接正题,先看源码。
/
public interface ViewManager
{
public void addView(View view, ViewGroup.LayoutParams params);
public void updateViewLayout(View view, ViewGroup.LayoutParams params);
public void removeView(View view);
}
/
public interface WindowManager extends ViewManager
/
public abstract class ViewGroup extends View implements ViewParent, ViewManager
/
public class LinearLayout extends ViewGroup
/
public class LocalActivityManager {
private static final String TAG = "LocalActivityManager";
private static final boolean localLOGV = false || Config.LOGV;
// Internal token for an Activity being managed by LocalActivityManager.
private static class LocalActivityRecord extends Binder {
LocalActivityRecord(String _id, Intent _intent) {
id = _id;
intent = _intent;
}
final String id; // Unique name of this record.
Intent intent; // Which activity to run here.
ActivityInfo activityInfo; // Package manager info about activity.
Activity activity; // Currently instantiated activity.
Window window; // Activity's top-level window.
Bundle instanceState; // Last retrieved freeze state.
int curState = RESTORED; // Current state the activity is in.
}
/** The activity that is currently resumed. */
private LocalActivityRecord mResumed;
/** id -> record of all known activities. */
private final Map<String, LocalActivityRecord> mActivities
= new HashMap<String, LocalActivityRecord>();
.......
.......
}
/
public class ActivityGroup extends Activity
/
Activity是聚合类,包含了一个window对象,一个View,一个WindowManager对象。Activity的界面那些都是由包含对象完成的。
Window对象里面包含一个View对象。
ViewGroup里面包含一个View的child数组。
-----ActivityGroup的实现,包含一个LocalActivityManager 对象;。
ActivityGroup的原理是把要显示的activity的window的View添加到自己的LinearLayout 里面,进行的操作显示;而把activity对象保存到LocalActivityManager 对象里面。
实现过程:1、LinearLayout 的获取,这个是一个ViewGroup,也是一个View,通过ActivityGroup的window里面的view的findViewById方法获取一个id相等的,这个是View里面的方法
protected View findViewTraversal(int id) {
if (id == mID) {
return this;
}
return null;
}。
2、View的获取,通过LocalActivityManager 对象管理Activity,LocalActivityManager 的startActivity方法会增加一个LocalActivityRecord 对象,并返回一个原activity的window对象,public Window startActivity(String id, Intent intent)。然后把获取的这个Window里面的View对象添加到第1步ActivityGroup的LinearLayout ,就可以显示这个开始的Activity的界面。